shared/install: rework error propagation again
The immediate impulse for this change is the fedora scriptlet which called: /usr/lib/systemd/systemd-update-helper install-system-units cryptsetup-pre.target cryptsetup.target getty@.service ... system-systemd\x2dcryptsetup.slice system-systemd\x2dveritysetup.slice ... which called systemctl preset cryptsetup-pre.target cryptsetup.target getty@.service ... system-systemd\x2dcryptsetup.slice system-systemd\x2dveritysetup.slice ... which threw an error that system-systemdx2dcryptsetup.slice does not exist and did nothing at all. (The backslash is consumed by the shell.) The obvious fix here is to figure out more levels of escaping… But we should do something more robust in such cases. If we fail in processing of a single unit, let preset all continue processing units, report the failure through 'changes'. At the end, return failure. In general, for operations which operate on a list of units specified by the user, fail the whole operation if any of the individual operations failed. The only operation where we don't do this is 'preset-all'. $ SYSTEMD_LOG_LEVEL=debug build/systemctl --root=/ preset asdf1.servie asdf2.path; echo $? Cannot find unit asdf1.servie.service. Cannot find unit asdf2.path. Failed to preset unit: Unit asdf1.servie.service does not exist Failed to preset unit: Unit asdf2.path does not exist 1 While at it, fix double logging in the manager: dump_unit_changes() already logs about errors, so the manager should only log on success.
This commit is contained in:
+2
-5
@@ -1946,11 +1946,8 @@ static void manager_preset_all(Manager *m) {
|
||||
log_info("Applying preset policy.");
|
||||
r = unit_file_preset_all(RUNTIME_SCOPE_SYSTEM, /* file_flags= */ 0,
|
||||
/* root_dir= */ NULL, mode, &changes, &n_changes);
|
||||
install_changes_dump(r, "preset", changes, n_changes, /* quiet= */ false);
|
||||
if (r < 0)
|
||||
log_full_errno(r == -EEXIST ? LOG_NOTICE : LOG_WARNING, r,
|
||||
"Failed to populate /etc with preset unit settings, ignoring: %m");
|
||||
else
|
||||
r = install_changes_dump(r, "preset all", changes, n_changes, /* quiet= */ false);
|
||||
if (r >= 0)
|
||||
log_info("Populated /etc with preset unit settings.");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user