1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-19 22:50:17 +03:00

various: use RET_GATHER

No functional change indentended.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2023-07-09 13:32:24 -06:00
parent 809c3a84e1
commit 9ef648cca1
10 changed files with 61 additions and 122 deletions

View 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;
}

View 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();

View 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;

View 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;

View 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);
}
}

View 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;
}

View 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;

View 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;
}

View 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;
}

View 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);
}
}