From: Zbigniew Jędrzejewski-Szmek Date: Sun, 9 Jul 2023 19:32:24 +0000 (-0600) Subject: various: use RET_GATHER X-Git-Tag: v255-rc1~908^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ef648cca140632184d11c34d460e2fce066cddd;p=thirdparty%2Fsystemd.git various: use RET_GATHER No functional change indentended. --- diff --git a/src/analyze/analyze-security.c b/src/analyze/analyze-security.c index 1fcdbf9cd32..5408cfdeaab 100644 --- a/src/analyze/analyze-security.c +++ b/src/analyze/analyze-security.c @@ -2726,8 +2726,7 @@ static int offline_security_checks( k = verify_prepare_filename(*filename, &prepared); if (k < 0) { log_warning_errno(k, "Failed to prepare filename %s: %m", *filename); - if (r == 0) - r = k; + RET_GATHER(r, k); continue; } @@ -2760,19 +2759,15 @@ static int offline_security_checks( k = manager_load_startable_unit_or_warn(m, NULL, prepared, &units[count]); if (k < 0) { - if (r == 0) - r = k; + RET_GATHER(r, k); continue; } count++; } - for (size_t i = 0; i < count; i++) { - k = offline_security_check(units[i], threshold, policy, pager_flags, json_format_flags); - if (k < 0 && r == 0) - r = k; - } + for (size_t i = 0; i < count; i++) + RET_GATHER(r, offline_security_check(units[i], threshold, policy, pager_flags, json_format_flags)); return r; } diff --git a/src/analyze/analyze-verify-util.c b/src/analyze/analyze-verify-util.c index 132a84649b3..ae4164d053c 100644 --- a/src/analyze/analyze-verify-util.c +++ b/src/analyze/analyze-verify-util.c @@ -157,32 +157,23 @@ int verify_executable(Unit *u, const ExecCommand *exec, const char *root) { } static int verify_executables(Unit *u, const char *root) { - ExecCommand *exec; - int r = 0, k; - unsigned i; + int r = 0; assert(u); - exec = u->type == UNIT_SOCKET ? SOCKET(u)->control_command : + ExecCommand *exec = + u->type == UNIT_SOCKET ? SOCKET(u)->control_command : u->type == UNIT_MOUNT ? MOUNT(u)->control_command : u->type == UNIT_SWAP ? SWAP(u)->control_command : NULL; - k = verify_executable(u, exec, root); - if (k < 0 && r == 0) - r = k; + RET_GATHER(r, verify_executable(u, exec, root)); if (u->type == UNIT_SERVICE) - for (i = 0; i < ELEMENTSOF(SERVICE(u)->exec_command); i++) { - k = verify_executable(u, SERVICE(u)->exec_command[i], root); - if (k < 0 && r == 0) - r = k; - } + for (unsigned i = 0; i < ELEMENTSOF(SERVICE(u)->exec_command); i++) + RET_GATHER(r, verify_executable(u, SERVICE(u)->exec_command[i], root)); if (u->type == UNIT_SOCKET) - for (i = 0; i < ELEMENTSOF(SOCKET(u)->exec_command); i++) { - k = verify_executable(u, SOCKET(u)->exec_command[i], root); - if (k < 0 && r == 0) - r = k; - } + for (unsigned i = 0; i < ELEMENTSOF(SOCKET(u)->exec_command); i++) + RET_GATHER(r, verify_executable(u, SOCKET(u)->exec_command[i], root)); return r; } @@ -215,7 +206,7 @@ static int verify_documentation(Unit *u, bool check_man) { static int verify_unit(Unit *u, bool check_man, const char *root) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; - int r, k; + int r; assert(u); @@ -227,17 +218,9 @@ static int verify_unit(Unit *u, bool check_man, const char *root) { if (r < 0) log_unit_error_errno(u, r, "Failed to create %s/start: %s", u->id, bus_error_message(&error, r)); - k = verify_socket(u); - if (k < 0 && r == 0) - r = k; - - k = verify_executables(u, root); - if (k < 0 && r == 0) - r = k; - - k = verify_documentation(u, check_man); - if (k < 0 && r == 0) - r = k; + RET_GATHER(r, verify_socket(u)); + RET_GATHER(r, verify_executables(u, root)); + RET_GATHER(r, verify_documentation(u, check_man)); return r; } @@ -267,7 +250,7 @@ int verify_units( _unused_ _cleanup_(clear_log_syntax_callback) dummy_t dummy; Unit *units[strv_length(filenames)]; _cleanup_free_ char *var = NULL; - int r, k, i, count = 0; + int r, k, count = 0; if (strv_isempty(filenames)) return 0; @@ -306,26 +289,21 @@ int verify_units( k = verify_prepare_filename(*filename, &prepared); if (k < 0) { log_error_errno(k, "Failed to prepare filename %s: %m", *filename); - if (r == 0) - r = k; + RET_GATHER(r, k); continue; } k = manager_load_startable_unit_or_warn(m, NULL, prepared, &units[count]); if (k < 0) { - if (r == 0) - r = k; + RET_GATHER(r, k); continue; } count++; } - for (i = 0; i < count; i++) { - k = verify_unit(units[i], check_man, root); - if (k < 0 && r == 0) - r = k; - } + for (int i = 0; i < count; i++) + RET_GATHER(r, verify_unit(units[i], check_man, root)); if (s == POINTER_MAX) return log_oom(); diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c index e1ddf97914c..675ae185e24 100644 --- a/src/binfmt/binfmt.c +++ b/src/binfmt/binfmt.c @@ -100,9 +100,7 @@ static int apply_file(const char *filename, bool ignore_enoent) { if (strchr(COMMENTS, p[0])) continue; - k = apply_rule(filename, line, p); - if (k < 0 && r >= 0) - r = k; + RET_GATHER(r, apply_rule(filename, line, p)); } return r; @@ -201,7 +199,7 @@ static int binfmt_mounted_warn(void) { } static int run(int argc, char *argv[]) { - int r, k; + int r; r = parse_argv(argc, argv); if (r <= 0) @@ -221,11 +219,9 @@ static int run(int argc, char *argv[]) { if (r <= 0) return r; - for (int i = optind; i < argc; i++) { - k = apply_file(argv[i], false); - if (k < 0 && r >= 0) - r = k; - } + for (int i = optind; i < argc; i++) + RET_GATHER(r, apply_file(argv[i], false)); + } else { _cleanup_strv_free_ char **files = NULL; @@ -250,11 +246,8 @@ static int run(int argc, char *argv[]) { else log_debug("Flushed all binfmt_misc rules."); - STRV_FOREACH(f, files) { - k = apply_file(*f, true); - if (k < 0 && r >= 0) - r = k; - } + STRV_FOREACH(f, files) + RET_GATHER(r, apply_file(*f, true)); } return r; diff --git a/src/boot/bootctl-install.c b/src/boot/bootctl-install.c index 397db7d3a2e..7e85c2f08e2 100644 --- a/src/boot/bootctl-install.c +++ b/src/boot/bootctl-install.c @@ -421,8 +421,7 @@ static int install_binaries(const char *esp_path, const char *arch, bool force) * newer version, or other boot loader in place. */ if (arg_graceful && IN_SET(k, -ESTALE, -ESRCH)) continue; - if (k < 0 && r == 0) - r = k; + RET_GATHER(r, k); } return r; diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 660a98ab92e..903b74c45f6 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -736,8 +736,7 @@ static int do_daemon_reload(void) { k = bus_call_method(bus, bus_systemd_mgr, "StartUnit", &error, NULL, "ss", unit, "replace"); if (k < 0) { log_error_errno(k, "Failed to (re)start %s: %s", unit, bus_error_message(&error, r)); - if (r == 0) - r = k; + RET_GATHER(r, k); } } diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index df6812bb8a2..717dc195c56 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -1448,19 +1448,16 @@ on_error: int sd_dhcp_server_forcerenew(sd_dhcp_server *server) { DHCPLease *lease; - int k, r = 0; + int r = 0; assert_return(server, -EINVAL); log_dhcp_server(server, "FORCERENEW"); - HASHMAP_FOREACH(lease, server->bound_leases_by_client_id) { - k = server_send_forcerenew(server, lease->address, lease->gateway, - lease->htype, lease->hlen, lease->chaddr); - if (k < 0) - r = k; - } - + HASHMAP_FOREACH(lease, server->bound_leases_by_client_id) + RET_GATHER(r, + server_send_forcerenew(server, lease->address, lease->gateway, + lease->htype, lease->hlen, lease->chaddr)); return r; } diff --git a/src/libsystemd/sd-netlink/netlink-message-nfnl.c b/src/libsystemd/sd-netlink/netlink-message-nfnl.c index 582f623efe7..a8cec2bd8bd 100644 --- a/src/libsystemd/sd-netlink/netlink-message-nfnl.c +++ b/src/libsystemd/sd-netlink/netlink-message-nfnl.c @@ -184,7 +184,7 @@ int sd_nfnl_call_batch( _cleanup_free_ sd_netlink_message **replies = NULL; _cleanup_free_ uint32_t *serials = NULL; - int k, r; + int r; assert_return(nfnl, -EINVAL); assert_return(!netlink_pid_changed(nfnl), -ECHILD); @@ -201,11 +201,9 @@ int sd_nfnl_call_batch( if (r < 0) return r; - for (size_t i = 0; i < n_messages; i++) { - k = sd_netlink_read(nfnl, serials[i], usec, ret_messages ? replies + i : NULL); - if (k < 0 && r >= 0) - r = k; - } + for (size_t i = 0; i < n_messages; i++) + RET_GATHER(r, + sd_netlink_read(nfnl, serials[i], usec, ret_messages ? replies + i : NULL)); if (r < 0) return r; diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c index c9b277b124a..ca41f02fdd5 100644 --- a/src/sysctl/sysctl.c +++ b/src/sysctl/sysctl.c @@ -113,7 +113,7 @@ static int sysctl_write_or_warn(const char *key, const char *value, bool ignore_ static int apply_glob_option_with_prefix(OrderedHashmap *sysctl_options, Option *option, const char *prefix) { _cleanup_strv_free_ char **paths = NULL; _cleanup_free_ char *pattern = NULL; - int r, k; + int r; assert(sysctl_options); assert(option); @@ -173,28 +173,23 @@ static int apply_glob_option_with_prefix(OrderedHashmap *sysctl_options, Option continue; } - k = sysctl_write_or_warn(key, option->value, - /* ignore_failure = */ option->ignore_failure, - /* ignore_enoent = */ !arg_strict); - if (k < 0 && r >= 0) - r = k; + RET_GATHER(r, + sysctl_write_or_warn(key, option->value, + /* ignore_failure = */ option->ignore_failure, + /* ignore_enoent = */ !arg_strict)); } return r; } static int apply_glob_option(OrderedHashmap *sysctl_options, Option *option) { - int r = 0, k; + int r = 0; if (strv_isempty(arg_prefixes)) return apply_glob_option_with_prefix(sysctl_options, option, NULL); - STRV_FOREACH(i, arg_prefixes) { - k = apply_glob_option_with_prefix(sysctl_options, option, *i); - if (k < 0 && r >= 0) - r = k; - } - + STRV_FOREACH(i, arg_prefixes) + RET_GATHER(r, apply_glob_option_with_prefix(sysctl_options, option, *i)); return r; } @@ -215,8 +210,7 @@ static int apply_all(OrderedHashmap *sysctl_options) { k = sysctl_write_or_warn(option->key, option->value, /* ignore_failure = */ option->ignore_failure, /* ignore_enoent = */ !arg_strict); - if (k < 0 && r >= 0) - r = k; + RET_GATHER(r, k); } return r; @@ -444,7 +438,7 @@ static int parse_argv(int argc, char *argv[]) { static int run(int argc, char *argv[]) { _cleanup_ordered_hashmap_free_ OrderedHashmap *sysctl_options = NULL; - int r, k; + int r; r = parse_argv(argc, argv); if (r <= 0) @@ -455,15 +449,11 @@ static int run(int argc, char *argv[]) { umask(0022); if (argc > optind) { - int i; - r = 0; - for (i = optind; i < argc; i++) { - k = parse_file(&sysctl_options, argv[i], false); - if (k < 0 && r == 0) - r = k; - } + for (int i = optind; i < argc; i++) + RET_GATHER(r, parse_file(&sysctl_options, argv[i], false)); + } else { _cleanup_strv_free_ char **files = NULL; @@ -477,20 +467,13 @@ static int run(int argc, char *argv[]) { return cat_files(NULL, files, 0); } - STRV_FOREACH(f, files) { - k = parse_file(&sysctl_options, *f, true); - if (k < 0 && r == 0) - r = k; - } + STRV_FOREACH(f, files) + RET_GATHER(r, parse_file(&sysctl_options, *f, true)); - k = read_credential_lines(&sysctl_options); - if (k < 0 && r == 0) - r = k; + RET_GATHER(r, read_credential_lines(&sysctl_options)); } - k = apply_all(sysctl_options); - if (k < 0 && r == 0) - r = k; + RET_GATHER(r, apply_all(sysctl_options)); return r; } diff --git a/src/systemctl/systemctl-set-property.c b/src/systemctl/systemctl-set-property.c index b8d702ac0e8..5f4b810525c 100644 --- a/src/systemctl/systemctl-set-property.c +++ b/src/systemctl/systemctl-set-property.c @@ -46,7 +46,7 @@ static int set_property_one(sd_bus *bus, const char *name, char **properties) { int verb_set_property(int argc, char *argv[], void *userdata) { sd_bus *bus; _cleanup_strv_free_ char **names = NULL; - int r, k; + int r; r = acquire_bus(BUS_MANAGER, &bus); if (r < 0) @@ -59,10 +59,7 @@ int verb_set_property(int argc, char *argv[], void *userdata) { return log_error_errno(r, "Failed to expand '%s' into names: %m", argv[1]); r = 0; - STRV_FOREACH(name, names) { - k = set_property_one(bus, *name, strv_skip(argv, 2)); - if (k < 0 && r >= 0) - r = k; - } + STRV_FOREACH(name, names) + RET_GATHER(r, set_property_one(bus, *name, strv_skip(argv, 2))); return r; } diff --git a/src/udev/udev-builtin-uaccess.c b/src/udev/udev-builtin-uaccess.c index 36c993cbb08..da42ef59b03 100644 --- a/src/udev/udev-builtin-uaccess.c +++ b/src/udev/udev-builtin-uaccess.c @@ -12,6 +12,7 @@ #include "device-util.h" #include "devnode-acl.h" +#include "errno-util.h" #include "login-util.h" #include "log.h" #include "udev-builtin.h" @@ -66,8 +67,7 @@ finish: k = devnode_acl(path, true, false, 0, false, 0); if (k < 0) { log_device_full_errno(dev, k == -ENOENT ? LOG_DEBUG : LOG_ERR, k, "Failed to apply ACL: %m"); - if (r >= 0) - r = k; + RET_GATHER(r, k); } }