Skip to content

Commit 672226b

Browse files
committed
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 systemd/systemd#21224. (cherry picked from commit a4f0e0d)
1 parent 9333db0 commit 672226b

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

src/shared/install.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,11 @@ void install_changes_dump(int r, const char *verb, const InstallChange *changes,
435435
err = log_error_errno(changes[i].type, "Failed to %s unit, unit %s does not exist.",
436436
verb, changes[i].path);
437437
break;
438+
case -ENOLINK:
439+
err = log_error_errno(changes[i].type, "Failed to %s unit, %s is an unresolvable alias.",
440+
verb, changes[i].path);
441+
break;
442+
438443
case -EUNATCH:
439444
err = log_error_errno(changes[i].type, "Failed to %s unit, cannot resolve specifiers in \"%s\".",
440445
verb, changes[i].path);
@@ -3600,31 +3605,43 @@ int unit_file_preset_all(
36003605
if (r < 0)
36013606
return r;
36023607

3608+
r = 0;
36033609
STRV_FOREACH(i, lp.search_path) {
36043610
_cleanup_closedir_ DIR *d = NULL;
36053611

36063612
d = opendir(*i);
36073613
if (!d) {
3608-
if (errno == ENOENT)
3609-
continue;
3610-
3611-
return -errno;
3614+
if (errno != ENOENT)
3615+
RET_GATHER(r, -errno);
3616+
continue;
36123617
}
36133618

3614-
FOREACH_DIRENT(de, d, return -errno) {
3619+
FOREACH_DIRENT(de, d, RET_GATHER(r, -errno)) {
3620+
int k;
36153621

36163622
if (!unit_name_is_valid(de->d_name, UNIT_NAME_ANY))
36173623
continue;
36183624

36193625
if (!IN_SET(de->d_type, DT_LNK, DT_REG))
36203626
continue;
36213627

3622-
r = preset_prepare_one(scope, &plus, &minus, &lp, de->d_name, &presets, changes, n_changes);
3623-
if (r < 0 &&
3624-
!IN_SET(r, -EEXIST, -ERFKILL, -EADDRNOTAVAIL, -EBADSLT, -EIDRM, -EUCLEAN, -ELOOP, -ENOENT, -EUNATCH, -EXDEV))
3628+
k = preset_prepare_one(scope, &plus, &minus, &lp, de->d_name, &presets, changes, n_changes);
3629+
if (k < 0 &&
3630+
!IN_SET(k, -EEXIST,
3631+
-ERFKILL,
3632+
-EADDRNOTAVAIL,
3633+
-ETXTBSY,
3634+
-EBADSLT,
3635+
-EIDRM,
3636+
-EUCLEAN,
3637+
-ELOOP,
3638+
-EXDEV,
3639+
-ENOENT,
3640+
-ENOLINK,
3641+
-EUNATCH))
36253642
/* Ignore generated/transient/missing/invalid units when applying preset, propagate other errors.
3626-
* Coordinate with install_changes_dump() above. */
3627-
return r;
3643+
* Coordinate with install_change_dump_error() above. */
3644+
RET_GATHER(r, k);
36283645
}
36293646
}
36303647

0 commit comments

Comments
 (0)