diff options
author | Michal Schmidt <mschmidt@redhat.com> | 2014-11-28 18:50:43 +0100 |
---|---|---|
committer | Michal Schmidt <mschmidt@redhat.com> | 2014-11-28 18:56:16 +0100 |
commit | f647962d64e844689f3e2acfce6102fc47e76df2 (patch) | |
tree | dcaf5e38de1d4e31f73f540bc85532ceb72cfa6b /src/shared | |
parent | e80733be33e52d8ab2f1ae845326d39c600f5612 (diff) |
treewide: yet more log_*_errno + return simplifications
Using:
find . -name '*.[ch]' | while read f; do perl -i.mmm -e \
'local $/;
local $_=<>;
s/(if\s*\([^\n]+\))\s*{\n(\s*)(log_[a-z_]*_errno\(\s*([->a-zA-Z_]+)\s*,[^;]+);\s*return\s+\g4;\s+}/\1\n\2return \3;/msg;
print;'
$f
done
And a couple of manual whitespace fixups.
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/capability.c | 6 | ||||
-rw-r--r-- | src/shared/generator.c | 6 | ||||
-rw-r--r-- | src/shared/install.c | 6 | ||||
-rw-r--r-- | src/shared/logs-show.c | 72 | ||||
-rw-r--r-- | src/shared/socket-label.c | 6 | ||||
-rw-r--r-- | src/shared/socket-util.c | 6 | ||||
-rw-r--r-- | src/shared/util.c | 18 |
7 files changed, 40 insertions, 80 deletions
diff --git a/src/shared/capability.c b/src/shared/capability.c index 89e61430b0..b7e055318a 100644 --- a/src/shared/capability.c +++ b/src/shared/capability.c @@ -254,10 +254,8 @@ int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities) { } r = capability_bounding_set_drop(~keep_capabilities, true); - if (r < 0) { - log_error_errno(r, "Failed to drop capabilities: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to drop capabilities: %m"); d = cap_init(); if (!d) diff --git a/src/shared/generator.c b/src/shared/generator.c index f54bb06f68..2cb4d111f1 100644 --- a/src/shared/generator.c +++ b/src/shared/generator.c @@ -54,10 +54,8 @@ int generator_write_fsck_deps( /* treat missing check as essentially OK */ log_debug_errno(r, "Checking was requested for %s, but fsck.%s does not exist: %m", what, fstype); return 0; - } else if (r < 0) { - log_warning_errno(r, "Checking was requested for %s, but fsck.%s cannot be used: %m", what, fstype); - return r; - } + } else if (r < 0) + return log_warning_errno(r, "Checking was requested for %s, but fsck.%s cannot be used: %m", what, fstype); } if (streq(where, "/")) { diff --git a/src/shared/install.c b/src/shared/install.c index 9094662dfc..af35b29df3 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -1553,10 +1553,8 @@ int unit_file_add_dependency( UnitFileState state; state = unit_file_get_state(scope, root_dir, *i); - if (state < 0) { - log_error_errno(state, "Failed to get unit file state for %s: %m", *i); - return state; - } + if (state < 0) + return log_error_errno(state, "Failed to get unit file state for %s: %m", *i); if (state == UNIT_FILE_MASKED || state == UNIT_FILE_MASKED_RUNTIME) { log_error("Failed to enable unit: Unit %s is masked", *i); diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 16ea1bb782..2da4ef3e12 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -295,10 +295,8 @@ static int output_short( if (r < 0) r = sd_journal_get_monotonic_usec(j, &t, &boot_id); - if (r < 0) { - log_error_errno(r, "Failed to get monotonic timestamp: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to get monotonic timestamp: %m"); fprintf(f, "[%5llu.%06llu]", (unsigned long long) (t / USEC_PER_SEC), @@ -322,10 +320,8 @@ static int output_short( if (r < 0) r = sd_journal_get_realtime_usec(j, &x); - if (r < 0) { - log_error_errno(r, "Failed to get realtime timestamp: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to get realtime timestamp: %m"); t = (time_t) (x / USEC_PER_SEC); @@ -440,10 +436,8 @@ static int output_verbose( } r = sd_journal_get_cursor(j, &cursor); - if (r < 0) { - log_error_errno(r, "Failed to get cursor: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to get cursor: %m"); fprintf(f, "%s [%s]\n", flags & OUTPUT_UTC ? @@ -515,22 +509,16 @@ static int output_export( sd_journal_set_data_threshold(j, 0); r = sd_journal_get_realtime_usec(j, &realtime); - if (r < 0) { - log_error_errno(r, "Failed to get realtime timestamp: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to get realtime timestamp: %m"); r = sd_journal_get_monotonic_usec(j, &monotonic, &boot_id); - if (r < 0) { - log_error_errno(r, "Failed to get monotonic timestamp: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to get monotonic timestamp: %m"); r = sd_journal_get_cursor(j, &cursor); - if (r < 0) { - log_error_errno(r, "Failed to get cursor: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to get cursor: %m"); fprintf(f, "__CURSOR=%s\n" @@ -655,22 +643,16 @@ static int output_json( sd_journal_set_data_threshold(j, flags & OUTPUT_SHOW_ALL ? 0 : JSON_THRESHOLD); r = sd_journal_get_realtime_usec(j, &realtime); - if (r < 0) { - log_error_errno(r, "Failed to get realtime timestamp: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to get realtime timestamp: %m"); r = sd_journal_get_monotonic_usec(j, &monotonic, &boot_id); - if (r < 0) { - log_error_errno(r, "Failed to get monotonic timestamp: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to get monotonic timestamp: %m"); r = sd_journal_get_cursor(j, &cursor); - if (r < 0) { - log_error_errno(r, "Failed to get cursor: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to get cursor: %m"); if (mode == OUTPUT_JSON_PRETTY) fprintf(f, @@ -1224,24 +1206,18 @@ int add_match_this_boot(sd_journal *j, const char *machine) { if (machine) { r = get_boot_id_for_machine(machine, &boot_id); - if (r < 0) { - log_error_errno(r, "Failed to get boot id of container %s: %m", machine); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to get boot id of container %s: %m", machine); } else { r = sd_id128_get_boot(&boot_id); - if (r < 0) { - log_error_errno(r, "Failed to get boot id: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to get boot id: %m"); } sd_id128_to_string(boot_id, match + 9); r = sd_journal_add_match(j, match, strlen(match)); - if (r < 0) { - log_error_errno(r, "Failed to add match: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to add match: %m"); r = sd_journal_add_conjunction(j); if (r < 0) diff --git a/src/shared/socket-label.c b/src/shared/socket-label.c index 7a03ac0c51..815b90fdfb 100644 --- a/src/shared/socket-label.c +++ b/src/shared/socket-label.c @@ -161,10 +161,8 @@ int make_socket_fd(int log_level, const char* address, int flags) { _cleanup_free_ char *p = NULL; r = socket_address_print(&a, &p); - if (r < 0) { - log_error_errno(r, "socket_address_print(): %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "socket_address_print(): %m"); if (fd < 0) log_error_errno(fd, "Failed to listen on %s: %m", p); diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c index 0bb34f7826..6bdcb99205 100644 --- a/src/shared/socket-util.c +++ b/src/shared/socket-util.c @@ -636,10 +636,8 @@ int socknameinfo_pretty(union sockaddr_union *sa, socklen_t salen, char **_ret) int saved_errno = errno; r = sockaddr_pretty(&sa->sa, salen, true, &ret); - if (r < 0) { - log_error_errno(r, "sockadd_pretty() failed: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "sockadd_pretty() failed: %m"); log_debug_errno(saved_errno, "getnameinfo(%s) failed: %m", ret); } else { diff --git a/src/shared/util.c b/src/shared/util.c index 646787cd79..74dd4b7f4e 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -3795,10 +3795,8 @@ int wait_for_terminate_and_warn(const char *name, pid_t pid) { assert(pid > 1); r = wait_for_terminate(pid, &status); - if (r < 0) { - log_warning_errno(r, "Failed to wait for %s: %m", name); - return r; - } + if (r < 0) + return log_warning_errno(r, "Failed to wait for %s: %m", name); if (status.si_code == CLD_EXITED) { if (status.si_status != 0) { @@ -5506,16 +5504,12 @@ int make_console_stdio(void) { /* Make /dev/console the controlling terminal and stdin/stdout/stderr */ fd = acquire_terminal("/dev/console", false, true, true, USEC_INFINITY); - if (fd < 0) { - log_error_errno(fd, "Failed to acquire terminal: %m"); - return fd; - } + if (fd < 0) + return log_error_errno(fd, "Failed to acquire terminal: %m"); r = make_stdio(fd); - if (r < 0) { - log_error_errno(r, "Failed to duplicate terminal fd: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to duplicate terminal fd: %m"); return 0; } |