1
0
mirror of https://github.com/systemd/systemd synced 2024-07-01 07:34:28 +00:00

shared/install: use RET_GATHER more

This commit is contained in:
Mike Yuan 2024-02-29 18:53:26 +08:00
parent 7dfc71399d
commit b2751cf039
No known key found for this signature in database
GPG Key ID: 417471C0A40F58B3

View File

@ -1892,7 +1892,7 @@ static int install_info_symlink_alias(
InstallChange **changes,
size_t *n_changes) {
int r = 0, q;
int r, ret = 0;
assert(info);
assert(lp);
@ -1900,20 +1900,17 @@ static int install_info_symlink_alias(
STRV_FOREACH(s, info->aliases) {
_cleanup_free_ char *alias_path = NULL, *dst = NULL, *dst_updated = NULL;
bool broken;
q = install_name_printf(scope, info, *s, &dst);
if (q < 0) {
install_changes_add(changes, n_changes, q, *s, NULL);
r = r < 0 ? r : q;
r = install_name_printf(scope, info, *s, &dst);
if (r < 0) {
RET_GATHER(ret, install_changes_add(changes, n_changes, r, *s, NULL));
continue;
}
q = unit_file_verify_alias(info, dst, &dst_updated, changes, n_changes);
if (q == -ELOOP)
continue;
if (q < 0) {
r = r < 0 ? r : q;
r = unit_file_verify_alias(info, dst, &dst_updated, changes, n_changes);
if (r < 0) {
if (r != -ELOOP)
RET_GATHER(ret, r);
continue;
}
@ -1921,18 +1918,18 @@ static int install_info_symlink_alias(
if (!alias_path)
return -ENOMEM;
q = chase(alias_path, lp->root_dir, CHASE_NONEXISTENT, NULL, NULL);
if (q < 0 && q != -ENOENT) {
r = r < 0 ? r : q;
bool broken;
r = chase(alias_path, lp->root_dir, CHASE_NONEXISTENT, /* ret_path = */ NULL, /* ret_fd = */ NULL);
if (r < 0 && r != -ENOENT) {
RET_GATHER(ret, r);
continue;
}
broken = q == 0; /* symlink target does not exist? */
broken = r == 0; /* symlink target does not exist? */
q = create_symlink(lp, info->path, alias_path, force || broken, changes, n_changes);
r = r < 0 ? r : q;
RET_GATHER(ret, create_symlink(lp, info->path, alias_path, force || broken, changes, n_changes));
}
return r;
return ret;
}
static int install_info_symlink_wants(
@ -1995,10 +1992,7 @@ static int install_info_symlink_wants(
q = install_name_printf(scope, info, *s, &dst);
if (q < 0) {
install_changes_add(changes, n_changes, q, *s, NULL);
if (r >= 0)
r = q;
RET_GATHER(r, install_changes_add(changes, n_changes, q, *s, NULL));
continue;
}
@ -2010,15 +2004,13 @@ static int install_info_symlink_wants(
* 'systemctl enable serial-getty@.service' should fail, the user should specify an
* instance like in 'systemctl enable serial-getty@ttyS0.service'.
*/
if (file_flags & UNIT_FILE_IGNORE_AUXILIARY_FAILURE)
if (FLAGS_SET(file_flags, UNIT_FILE_IGNORE_AUXILIARY_FAILURE))
continue;
if (unit_name_is_valid(dst, UNIT_NAME_ANY))
q = install_changes_add(changes, n_changes, -EIDRM, dst, n);
RET_GATHER(r, install_changes_add(changes, n_changes, -EIDRM, dst, n));
else
q = install_changes_add(changes, n_changes, -EUCLEAN, dst, NULL);
if (r >= 0)
r = q;
RET_GATHER(r, install_changes_add(changes, n_changes, -EUCLEAN, dst, NULL));
continue;
}
@ -2027,7 +2019,7 @@ static int install_info_symlink_wants(
if (!path)
return -ENOMEM;
q = create_symlink(lp, info->path, path, true, changes, n_changes);
q = create_symlink(lp, info->path, path, /* force = */ true, changes, n_changes);
if ((q < 0 && r >= 0) || r == 0)
r = q;
@ -2418,7 +2410,7 @@ int unit_file_link(
_cleanup_strv_free_ char **todo = NULL;
const char *config_path;
size_t n_todo = 0;
int r, q;
int r;
assert(scope >= 0);
assert(scope < _RUNTIME_SCOPE_MAX);
@ -2487,9 +2479,7 @@ int unit_file_link(
if (!new_path)
return -ENOMEM;
q = create_symlink(&lp, *i, new_path, flags & UNIT_FILE_FORCE, changes, n_changes);
if (q < 0 && r >= 0)
r = q;
RET_GATHER(r, create_symlink(&lp, *i, new_path, flags & UNIT_FILE_FORCE, changes, n_changes));
}
return r;