aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/history.cpp
diff options
context:
space:
mode:
authorGravatar Jeff Kowalski <jeff.kowalski@gmail.com>2016-03-12 12:26:01 -0800
committerGravatar Jeff Kowalski <jeff.kowalski@gmail.com>2016-03-12 12:26:01 -0800
commita7012648fe64fe5e501a7439660684f93afcd60d (patch)
tree211e92d7a233508e4eaf89ecb435896e672eb8c7 /src/history.cpp
parent46b9f263ac780ae6a921fc24611c75bbec92ebca (diff)
Improve error handling around fchown
Address the feedback from the prior commit: - Change the sense of return value testing to match more common comparison idiom - Test result of fchmod as well as fchown - Change sense of return value testing around wrename as well - Include errno where possible in error message
Diffstat (limited to 'src/history.cpp')
-rw-r--r--src/history.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/history.cpp b/src/history.cpp
index 022524c3..75e42638 100644
--- a/src/history.cpp
+++ b/src/history.cpp
@@ -1453,16 +1453,19 @@ bool history_t::save_internal_via_rewrite()
if (wstat(new_name, &sbuf) >= 0)
{
/* Success */
- if (0 > fchown(out_fd, sbuf.st_uid, sbuf.st_gid))
+ if (fchown(out_fd, sbuf.st_uid, sbuf.st_gid) == -1)
{
- debug(2, L"Error when changing ownership of history file");
+ debug(2, L"Error %d when changing ownership of history file", errno);
+ }
+ if (fchmod(out_fd, sbuf.st_mode) == -1)
+ {
+ debug(2, L"Error %d when changing mode of history file", errno);
}
- fchmod(out_fd, sbuf.st_mode);
}
- if (0 > wrename(tmp_name, new_name))
+ if (wrename(tmp_name, new_name) == -1)
{
- debug(2, L"Error when renaming history file");
+ debug(2, L"Error %d when renaming history file", errno);
}
}
close(out_fd);