From 709f6e46a35ec492b70eb92943d82a8d838ce918 Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Thu, 5 Nov 2015 13:44:06 +0100 Subject: treewide: use the negative error codes returned by our functions Our functions return negative error codes. Do not rely on errno being set after calling our own functions. --- src/journal/catalog.c | 2 +- src/journal/coredump.c | 12 +++++++----- src/journal/coredumpctl.c | 4 ++-- src/journal/journal-verify.c | 6 +++--- src/journal/journalctl.c | 4 ++-- src/journal/journald-console.c | 2 +- src/journal/journald-native.c | 2 +- src/journal/journald-server.c | 9 +++++++-- 8 files changed, 24 insertions(+), 17 deletions(-) (limited to 'src/journal') diff --git a/src/journal/catalog.c b/src/journal/catalog.c index ef515fc2d7..8942d6ec44 100644 --- a/src/journal/catalog.c +++ b/src/journal/catalog.c @@ -208,7 +208,7 @@ int catalog_import_file(Hashmap *h, struct strbuf *sb, const char *path) { r = catalog_file_lang(path, &deflang); if (r < 0) - log_error_errno(errno, "Failed to determine language for file %s: %m", path); + log_error_errno(r, "Failed to determine language for file %s: %m", path); if (r == 1) log_debug("File %s has language %s.", path, deflang); diff --git a/src/journal/coredump.c b/src/journal/coredump.c index 2e543537f6..4c83e311db 100644 --- a/src/journal/coredump.c +++ b/src/journal/coredump.c @@ -139,6 +139,7 @@ static int fix_acl(int fd, uid_t uid) { _cleanup_(acl_freep) acl_t acl = NULL; acl_entry_t entry; acl_permset_t permset; + int r; assert(fd >= 0); @@ -160,11 +161,12 @@ static int fix_acl(int fd, uid_t uid) { } if (acl_get_permset(entry, &permset) < 0 || - acl_add_perm(permset, ACL_READ) < 0 || - calc_acl_mask_if_needed(&acl) < 0) { - log_warning_errno(errno, "Failed to patch ACL: %m"); - return -errno; - } + acl_add_perm(permset, ACL_READ) < 0) + return log_warning_errno(errno, "Failed to patch ACL: %m"); + + r = calc_acl_mask_if_needed(&acl); + if (r < 0) + return log_warning_errno(r, "Failed to patch ACL: %m"); if (acl_set_fd(fd, acl) < 0) return log_error_errno(errno, "Failed to apply ACL: %m"); diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c index af4d051138..1df28d774a 100644 --- a/src/journal/coredumpctl.c +++ b/src/journal/coredumpctl.c @@ -617,7 +617,7 @@ static int save_core(sd_journal *j, int fd, char **path, bool *unlink_temp) { fdt = mkostemp_safe(temp, O_WRONLY|O_CLOEXEC); if (fdt < 0) - return log_error_errno(errno, "Failed to create temporary file: %m"); + return log_error_errno(fdt, "Failed to create temporary file: %m"); log_debug("Created temporary file %s", temp); fd = fdt; @@ -776,7 +776,7 @@ static int run_gdb(sd_journal *j) { r = wait_for_terminate(pid, &st); if (r < 0) { - log_error_errno(errno, "Failed to wait for gdb: %m"); + log_error_errno(r, "Failed to wait for gdb: %m"); goto finish; } diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c index b78ce98b17..3676cb8788 100644 --- a/src/journal/journal-verify.c +++ b/src/journal/journal-verify.c @@ -842,19 +842,19 @@ int journal_file_verify( data_fd = open_tmpfile("/var/tmp", O_RDWR | O_CLOEXEC); if (data_fd < 0) { - r = log_error_errno(errno, "Failed to create data file: %m"); + r = log_error_errno(data_fd, "Failed to create data file: %m"); goto fail; } entry_fd = open_tmpfile("/var/tmp", O_RDWR | O_CLOEXEC); if (entry_fd < 0) { - r = log_error_errno(errno, "Failed to create entry file: %m"); + r = log_error_errno(entry_fd, "Failed to create entry file: %m"); goto fail; } entry_array_fd = open_tmpfile("/var/tmp", O_RDWR | O_CLOEXEC); if (entry_array_fd < 0) { - r = log_error_errno(errno, + r = log_error_errno(entry_array_fd, "Failed to create entry array file: %m"); goto fail; } diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 98a852cb50..277adba904 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -1483,7 +1483,7 @@ static int setup_keys(void) { safe_close(fd); fd = mkostemp_safe(k, O_WRONLY|O_CLOEXEC); if (fd < 0) { - r = log_error_errno(errno, "Failed to open %s: %m", k); + r = log_error_errno(fd, "Failed to open %s: %m", k); goto finish; } @@ -1491,7 +1491,7 @@ static int setup_keys(void) { * writing and in-place updating */ r = chattr_fd(fd, FS_SECRM_FL|FS_NODUMP_FL|FS_SYNC_FL|FS_NOCOW_FL, FS_SECRM_FL|FS_NODUMP_FL|FS_SYNC_FL|FS_NOCOW_FL); if (r < 0) - log_warning_errno(errno, "Failed to set file attributes: %m"); + log_warning_errno(r, "Failed to set file attributes: %m"); zero(h); memcpy(h.signature, "KSHHRHLP", 8); diff --git a/src/journal/journald-console.c b/src/journal/journald-console.c index 860832cfc8..89f3d4b42f 100644 --- a/src/journal/journald-console.c +++ b/src/journal/journald-console.c @@ -106,7 +106,7 @@ void server_forward_console( fd = open_terminal(tty, O_WRONLY|O_NOCTTY|O_CLOEXEC); if (fd < 0) { - log_debug_errno(errno, "Failed to open %s for logging: %m", tty); + log_debug_errno(fd, "Failed to open %s for logging: %m", tty); return; } diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c index b1fc875596..1e3774dafb 100644 --- a/src/journal/journald-native.c +++ b/src/journal/journald-native.c @@ -344,7 +344,7 @@ void server_process_native_file( r = readlink_malloc(sl, &k); if (r < 0) { - log_error_errno(errno, "readlink(%s) failed: %m", sl); + log_error_errno(r, "readlink(%s) failed: %m", sl); return; } diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 3fd25d1af4..7a70dcbc57 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -240,12 +240,17 @@ void server_fix_perms(Server *s, JournalFile *f, uid_t uid) { /* We do not recalculate the mask unconditionally here, * so that the fchmod() mask above stays intact. */ if (acl_get_permset(entry, &permset) < 0 || - acl_add_perm(permset, ACL_READ) < 0 || - calc_acl_mask_if_needed(&acl) < 0) { + acl_add_perm(permset, ACL_READ) < 0) { log_warning_errno(errno, "Failed to patch ACL on %s, ignoring: %m", f->path); return; } + r = calc_acl_mask_if_needed(&acl); + if (r < 0) { + log_warning_errno(r, "Failed to patch ACL on %s, ignoring: %m", f->path); + return; + } + if (acl_set_fd(f->fd, acl) < 0) log_warning_errno(errno, "Failed to set ACL on %s, ignoring: %m", f->path); -- cgit v1.2.3-54-g00ecf