|
Zbigniew Jędrzejewski-Szmek |
696e2f |
From 3f5a187dcf8ad2f0690046876d30d37630c11014 Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Date: Wed, 17 Aug 2016 22:15:54 -0400
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Subject: [PATCH] shared/install: properly report masked units listed in Also=
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
MIME-Version: 1.0
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Content-Type: text/plain; charset=UTF-8
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Content-Transfer-Encoding: 8bit
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
A masked unit is listed in Also=:
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
$ systemctl cat test1 test2
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
→# /etc/systemd/system/test1.service
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
[Unit]
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Description=test service 1
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
[Service]
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Type=oneshot
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
ExecStart=/usr/bin/true
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
[Install]
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
WantedBy=multi-user.target
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Also=test2.service
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Alias=alias1.service
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
→# /dev/null
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
$ systemctl --root=/ enable test1
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
(before)
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Created symlink /etc/systemd/system/alias1.service → /etc/systemd/system/test1.service.
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Created symlink /etc/systemd/system/multi-user.target.wants/test1.service → /etc/systemd/system/test1.service.
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
settings in the [Install] section, and DefaultInstance for template units).
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
This means they are not meant to be enabled using systemctl.
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Possible reasons for having this kind of units are:
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
1) A unit may be statically enabled by being symlinked from another unit's
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
.wants/ or .requires/ directory.
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
2) A unit's purpose may be to act as a helper for some other unit which has
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
a requirement dependency on it.
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
3) A unit may be started when needed via activation (socket, path, timer,
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
D-Bus, udev, scripted systemctl call, ...).
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
4) In case of template units, the unit is meant to be enabled with some
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
instance name specified.
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
(after)
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Created symlink /etc/systemd/system/alias1.service → /etc/systemd/system/test1.service.
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Created symlink /etc/systemd/system/multi-user.target.wants/test1.service → /etc/systemd/system/test1.service.
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Unit /etc/systemd/system/test2.service is masked, ignoring.
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
(cherry picked from commit f16517151310b88591f3501a59e23ae2a79e7f02)
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
---
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
src/shared/install.c | 11 +++++++++++
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
1 file changed, 11 insertions(+)
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
diff --git a/src/shared/install.c b/src/shared/install.c
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
index 9ce8e4d390..9d9f4dff4f 100644
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
--- a/src/shared/install.c
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+++ b/src/shared/install.c
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
@@ -1686,6 +1686,17 @@ static int install_context_apply(
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ /* We can attempt to process a masked unit when a different unit
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ * that we were processing specifies it in DefaultInstance= or Also=. */
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ if (i->type == UNIT_FILE_TYPE_MASKED) {
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ unit_file_changes_add(changes, n_changes, UNIT_FILE_IS_MASKED, i->path, NULL);
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ if (r >= 0)
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ /* Assume that some *could* have been enabled here, avoid
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ * "empty [Install] section" warning. */
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ r += 1;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ continue;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
if (i->type != UNIT_FILE_TYPE_REGULAR)
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
continue;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|