diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2024-05-07 18:54:24 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2024-05-08 08:18:55 +0200 |
commit | a4f0e0da3573a10bc5404142be8799418760b1d1 (patch) | |
tree | 462c7bad64babd5d51b5b9a509fc5052f4319e44 /src/shared/install.c | |
parent | Merge pull request #32684 from YHNdnzj/pr-followups (diff) | |
download | systemd-a4f0e0da3573a10bc5404142be8799418760b1d1.tar.xz systemd-a4f0e0da3573a10bc5404142be8799418760b1d1.zip |
preset-all: continue on errors, report more errors
Firstly, if we encounter an error when iterating over the directory, gather
the error but continue. This is unlikely to happen, but if it happens, then
it doesn't seem very useful to break the preset processing at a random
point. If we can't process a unit — too bad, but since we already might
have processed some units earlier, we might as well try to process the
remaining ones.
Secondly, add missing error codes for units that are in a bad state to the
exclusion list. Those, we report them in the changes list, but consider the
whole operation a success. (-ETXTBSY and -ENOLINK were missing.)
Thirdly, add a message generator for -ENOLINK.
Fixes https://github.com/systemd/systemd/issues/21224.
Diffstat (limited to 'src/shared/install.c')
-rw-r--r-- | src/shared/install.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/src/shared/install.c b/src/shared/install.c index 48860c7129..dd2bd5c948 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -440,6 +440,11 @@ int install_change_dump_error(const InstallChange *change, char **ret_errmsg, co bus_error = BUS_ERROR_NO_SUCH_UNIT; break; + case -ENOLINK: + m = strjoin("Unit ", change->path, " is an unresolvable alias"); + bus_error = BUS_ERROR_NO_SUCH_UNIT; + break; + case -EUNATCH: m = strjoin("Cannot resolve specifiers in unit ", change->path); bus_error = BUS_ERROR_BAD_UNIT_SETTING; @@ -3658,18 +3663,19 @@ int unit_file_preset_all( if (r < 0) return r; + r = 0; STRV_FOREACH(i, lp.search_path) { _cleanup_closedir_ DIR *d = NULL; d = opendir(*i); if (!d) { - if (errno == ENOENT) - continue; - - return -errno; + if (errno != ENOENT) + RET_GATHER(r, -errno); + continue; } - FOREACH_DIRENT(de, d, return -errno) { + FOREACH_DIRENT(de, d, RET_GATHER(r, -errno)) { + int k; if (!unit_name_is_valid(de->d_name, UNIT_NAME_ANY)) continue; @@ -3677,12 +3683,23 @@ int unit_file_preset_all( if (!IN_SET(de->d_type, DT_LNK, DT_REG)) continue; - r = preset_prepare_one(scope, &plus, &minus, &lp, de->d_name, &presets, changes, n_changes); - if (r < 0 && - !IN_SET(r, -EEXIST, -ERFKILL, -EADDRNOTAVAIL, -EBADSLT, -EIDRM, -EUCLEAN, -ELOOP, -ENOENT, -EUNATCH, -EXDEV)) + k = preset_prepare_one(scope, &plus, &minus, &lp, de->d_name, &presets, changes, n_changes); + if (k < 0 && + !IN_SET(k, -EEXIST, + -ERFKILL, + -EADDRNOTAVAIL, + -ETXTBSY, + -EBADSLT, + -EIDRM, + -EUCLEAN, + -ELOOP, + -EXDEV, + -ENOENT, + -ENOLINK, + -EUNATCH)) /* Ignore generated/transient/missing/invalid units when applying preset, propagate other errors. - * Coordinate with install_changes_dump() above. */ - return r; + * Coordinate with install_change_dump_error() above. */ + RET_GATHER(r, k); } } |