]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
various: use RET_GATHER
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 9 Jul 2023 19:32:24 +0000 (13:32 -0600)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 13 Jul 2023 09:12:00 +0000 (11:12 +0200)
No functional change indentended.

src/analyze/analyze-security.c
src/analyze/analyze-verify-util.c
src/binfmt/binfmt.c
src/boot/bootctl-install.c
src/fstab-generator/fstab-generator.c
src/libsystemd-network/sd-dhcp-server.c
src/libsystemd/sd-netlink/netlink-message-nfnl.c
src/sysctl/sysctl.c
src/systemctl/systemctl-set-property.c
src/udev/udev-builtin-uaccess.c

index 1fcdbf9cd32513761e1c473f6c44ef1f1f130a93..5408cfdeaabf099eaf4ec71932fef096e858e167 100644 (file)
@@ -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;
 }
index 132a84649b3d2ea023be52c8108634dff5a78a9d..ae4164d053c06a0e58b844687fdd65caa515e593 100644 (file)
@@ -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();
index e1ddf97914c9d8baf47f111de2847091fd08e102..675ae185e2486ce57cef82844b020ab22b01c297 100644 (file)
@@ -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;
index 397db7d3a2eeccbffb773bf39fea44f06c0b3de4..7e85c2f08e2612f4572fb6d9415a885d4d1f19ec 100644 (file)
@@ -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;
index 660a98ab92e502c04acbdd66c139d5b401c508f9..903b74c45f64f83a83452aee943c5ad75fad53c4 100644 (file)
@@ -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);
                 }
         }
 
index df6812bb8a255a6f532012784c08271de6e204c8..717dc195c5640d1238d2855e44f5750d3a7f9d3f 100644 (file)
@@ -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;
 }
 
index 582f623efe70fe66d8659801fac064177f8df3e5..a8cec2bd8bdf512782638718d268c19ce656b5f9 100644 (file)
@@ -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;
 
index c9b277b124aff394b947c1d562ad0462f5d99803..ca41f02fdd53cc400b73719090b7633c244945b0 100644 (file)
@@ -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;
 }
index b8d702ac0e8d53e9c4addb0eb8317cd75ef12861..5f4b810525cc22cce827db9bb9c84cf0d0fa7e21 100644 (file)
@@ -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;
 }
index 36c993cbb0839dd7167dbb196604e6fee9293793..da42ef59b035008f0ad37532da12b7d6aafb020c 100644 (file)
@@ -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);
                 }
         }