]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/install: properly report masked units listed in Also= 3955/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 18 Aug 2016 02:15:54 +0000 (22:15 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 19 Aug 2016 13:55:56 +0000 (09:55 -0400)
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.

src/shared/install.c

index 6c7eb9b2efb4696d9ba1940628bf1619379d1587..6a16f8985b897a727e1a7ba943c8a4536afc4439 100644 (file)
@@ -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;