richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
923a60
From 1f8b1e35e3ec80c50201403171b7375ff14c808c Mon Sep 17 00:00:00 2001
923a60
From: Michal Sekletar <msekletar@users.noreply.github.com>
923a60
Date: Tue, 26 Jul 2016 14:25:52 +0200
923a60
Subject: [PATCH] systemctl: allow disable on the unit file path, but warn
923a60
 about it (#3806)
923a60
923a60
systemd now returns an error when it is asked to perform disable on the
923a60
unit file path. In the past this was allowed, but systemd never really
923a60
considered an actual content of the [Install] section of the unit
923a60
file. Instead it performed disable on the unit name, i.e. purged all
923a60
symlinks pointing to the given unit file (undo of implicit link action
923a60
done by systemd when enable is called on the unit file path) and all
923a60
symlinks that have the same basename as the given unit file.
923a60
923a60
However, to notice that [Install] info of the file is not consulted one
923a60
must create additional symlinks manually. I argue that in most cases
923a60
users do not create such links. Let's be nice to our users and don't
923a60
break existing scripts that expect disable to work with the unit file
923a60
path.
923a60
923a60
Fixes #3706.
923a60
923a60
IMPORTANT
923a60
=========
923a60
Note that in this downstream backport we actually pass false to
923a60
normalize_names(), hence it will not produce any warning when full path
923a60
is passed in. This is because we need to preserve behavior compatible
923a60
with prior systemd versions shipped in RHEL.
923a60
923a60
Cherry-picked from: 1d3c86c06fca8311923fcf81af0ab0bbb66e1edd
923a60
Resolves: #1348208
923a60
---
923a60
 src/systemctl/systemctl.c | 29 +++++++++++++++++++++++++++++
923a60
 1 file changed, 29 insertions(+)
923a60
923a60
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
923a60
index b7496c006e..58998185c6 100644
923a60
--- a/src/systemctl/systemctl.c
923a60
+++ b/src/systemctl/systemctl.c
923a60
@@ -5333,6 +5333,29 @@ static int mangle_names(char **original_names, char ***mangled_names) {
923a60
         return 0;
923a60
 }
923a60
 
923a60
+static int normalize_names(char **names, bool warn_if_path) {
923a60
+        char **u;
923a60
+        bool was_path = false;
923a60
+
923a60
+        STRV_FOREACH(u, names) {
923a60
+                int r;
923a60
+
923a60
+                if (!is_path(*u))
923a60
+                        continue;
923a60
+
923a60
+                r = free_and_strdup(u, basename(*u));
923a60
+                if (r < 0)
923a60
+                        return log_error_errno(r, "Failed to normalize unit file path: %m");
923a60
+
923a60
+                was_path = true;
923a60
+        }
923a60
+
923a60
+        if (warn_if_path && was_path)
923a60
+                log_warning("Warning: Can't execute disable on the unit file path. Proceeding with the unit name.");
923a60
+
923a60
+        return 0;
923a60
+}
923a60
+
923a60
 static int enable_unit(sd_bus *bus, char **args) {
923a60
         _cleanup_strv_free_ char **names = NULL;
923a60
         const char *verb = args[0];
923a60
@@ -5357,6 +5380,12 @@ static int enable_unit(sd_bus *bus, char **args) {
923a60
         if (strv_isempty(names))
923a60
                 return 0;
923a60
 
923a60
+        if (streq(verb, "disable")) {
923a60
+                r = normalize_names(names, false);
923a60
+                if (r < 0)
923a60
+                        return r;
923a60
+        }
923a60
+
923a60
         if (!bus || avoid_bus()) {
923a60
                 if (streq(verb, "enable")) {
923a60
                         r = unit_file_enable(arg_scope, arg_runtime, arg_root, names, arg_force, &changes, &n_changes);