You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

82 lines
3.0 KiB

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