shared/install: properly report masked units listed in Also=
A masked unit is listed in Also=: $ systemctl cat test1 test2 →# /etc/systemd/system/test1.service [Unit] Description=test service 1 [Service] Type=oneshot ExecStart=/usr/bin/true [Install] WantedBy=multi-user.target Also=test2.service Alias=alias1.service →# /dev/null $ systemctl --root=/ enable test1 (before) Created symlink /etc/systemd/system/alias1.service → /etc/systemd/system/test1.service. Created symlink /etc/systemd/system/multi-user.target.wants/test1.service → /etc/systemd/system/test1.service. The unit files have no installation config (WantedBy, RequiredBy, Also, Alias settings in the [Install] section, and DefaultInstance for template units). This means they are not meant to be enabled using systemctl. Possible reasons for having this kind of units are: 1) A unit may be statically enabled by being symlinked from another unit's .wants/ or .requires/ directory. 2) A unit's purpose may be to act as a helper for some other unit which has a requirement dependency on it. 3) A unit may be started when needed via activation (socket, path, timer, D-Bus, udev, scripted systemctl call, ...). 4) In case of template units, the unit is meant to be enabled with some instance name specified. (after) Created symlink /etc/systemd/system/alias1.service → /etc/systemd/system/test1.service. Created symlink /etc/systemd/system/multi-user.target.wants/test1.service → /etc/systemd/system/test1.service. Unit /etc/systemd/system/test2.service is masked, ignoring.
This commit is contained in:
parent
de78fa9ba0
commit
f165171513
|
@ -1686,6 +1686,17 @@ static int install_context_apply(
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
/* We can attempt to process a masked unit when a different unit
|
||||
* that we were processing specifies it in DefaultInstance= or Also=. */
|
||||
if (i->type == UNIT_FILE_TYPE_MASKED) {
|
||||
unit_file_changes_add(changes, n_changes, UNIT_FILE_IS_MASKED, i->path, NULL);
|
||||
if (r >= 0)
|
||||
/* Assume that some *could* have been enabled here, avoid
|
||||
* "empty [Install] section" warning. */
|
||||
r += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i->type != UNIT_FILE_TYPE_REGULAR)
|
||||
continue;
|
||||
|
||||
|
|
Loading…
Reference in a new issue