|
Zbigniew Jędrzejewski-Szmek |
696e2f |
From 3cb3b0145ed8439eb604b43596e6456ed3292c46 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: Sun, 21 Aug 2016 09:10:51 -0400
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Subject: [PATCH] shared/install: do not enable masked instances (#4005)
|
|
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 |
When told to enable a template unit, and the DefaultInstance specified in that
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
unit was masked, we would do this. Such a unit cannot be started or loaded, so
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
reporting successful enabling is misleading and unexpected.
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
$ systemctl mask getty@tty1
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Created symlink /etc/systemd/system/getty@tty1.service → /dev/null.
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
$ systemctl --root=/ enable getty@tty1
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
(unchanged)
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Failed to enable unit, unit /etc/systemd/system/getty@tty1.service is masked.
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
$ systemctl --root=/ enable getty@
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
(before)
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Created symlink /etc/systemd/system/getty.target.wants/getty@tty1.service → /usr/lib/systemd/system/getty@.service.
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
(now)
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Failed to enable unit, unit /etc/systemd/system/getty@tty1.service is masked.
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
The same error is emitted for enable and preset. And an error is emmited, not a
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
warning, so the failure to enable DefaultInstance is treated the same as if the
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
instance was specified on the command line. I think that this makes most sense,
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
for most template units.
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
Fixes #2513.
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
(cherry picked from commit 047d91f9c8cf1bcf5a30f428668babd619533944)
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
---
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
src/shared/install.c | 35 ++++++++++++++++++++++++++++-------
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
1 file changed, 28 insertions(+), 7 deletions(-)
|
|
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 9d9f4dff4f..cb2a2e7e0d 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 |
@@ -912,8 +912,8 @@ static int install_info_may_process(
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
assert(i);
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
assert(paths);
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
- /* Checks whether the loaded unit file is one we should process, or is masked, transient or generated and thus
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
- * not subject to enable/disable operations. */
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ /* Checks whether the loaded unit file is one we should process, or is masked,
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ * transient or generated and thus not subject to enable/disable operations. */
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
if (i->type == UNIT_FILE_TYPE_MASKED) {
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
unit_file_changes_add(changes, n_changes, -ERFKILL, i->path, NULL);
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
@@ -1134,7 +1134,6 @@ static int unit_file_load(
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
struct stat st;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
int r;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
- assert(c);
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
assert(info);
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
assert(path);
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
@@ -1163,6 +1162,9 @@ static int unit_file_load(
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
return 0;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
}
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ /* c is only needed if we actually load the file */
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ assert(c);
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
if (fd < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
return -errno;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
@@ -1275,7 +1277,6 @@ static int unit_file_search(
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
char **p;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
int r;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
- assert(c);
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
assert(info);
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
assert(paths);
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
@@ -1546,7 +1547,14 @@ static int install_info_symlink_wants(
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
assert(paths);
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
assert(config_path);
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ if (strv_isempty(list))
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ return 0;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
if (unit_name_is_valid(i->name, UNIT_NAME_TEMPLATE)) {
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ UnitFileInstallInfo instance = {
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ .type = _UNIT_FILE_TYPE_INVALID,
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ };
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ _cleanup_free_ char *path = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
/* Don't install any symlink if there's no default
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
* instance configured */
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
@@ -1558,6 +1566,19 @@ static int install_info_symlink_wants(
|
|
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 |
+ instance.name = buf;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ r = unit_file_search(NULL, &instance, paths, SEARCH_FOLLOW_CONFIG_SYMLINKS);
|
|
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 |
+ path = instance.path;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ instance.path = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ if (instance.type == UNIT_FILE_TYPE_MASKED) {
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ unit_file_changes_add(changes, n_changes, -ERFKILL, path, NULL);
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ return -ERFKILL;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
n = buf;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
} else
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
n = i->name;
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
@@ -1687,12 +1708,12 @@ static int install_context_apply(
|
|
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 |
+ * that we were processing specifies it in 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 |
+ /* Assume that something *could* have been enabled here,
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
+ * avoid "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 |
2.9.0
|
|
Zbigniew Jędrzejewski-Szmek |
696e2f |
|