summaryrefslogtreecommitdiff
path: root/src/systemctl
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-02-19 16:52:09 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-02-19 17:42:18 -0500
commitb74df547a90a794ca75eea99238b9ae14a562720 (patch)
tree217c3342f65a7237c19fe715d575328134f044f8 /src/systemctl
parent1e94df447150f065241091044b32a730a5bf9ed4 (diff)
systemctl: when told to edit an instance, do not edit the template
Fixes #5383.
Diffstat (limited to 'src/systemctl')
-rw-r--r--src/systemctl/systemctl.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 60f8bc3df5..4fe2f126d8 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -6806,7 +6806,8 @@ static int find_paths_to_edit(sd_bus *bus, char **names, char ***paths) {
return r;
STRV_FOREACH(name, names) {
- _cleanup_free_ char *path = NULL, *new_path = NULL, *tmp_path = NULL;
+ _cleanup_free_ char *path = NULL, *new_path = NULL, *tmp_path = NULL, *tmp_name = NULL;
+ const char *unit_name;
r = unit_find_paths(bus, *name, &lp, &path, NULL);
if (r < 0)
@@ -6822,11 +6823,28 @@ static int find_paths_to_edit(sd_bus *bus, char **names, char ***paths) {
}
}
+ unit_name = basename(path);
+ /* We follow unit aliases, but we need to propagate the instance */
+ if (unit_name_is_valid(*name, UNIT_NAME_INSTANCE) &&
+ unit_name_is_valid(unit_name, UNIT_NAME_TEMPLATE)) {
+ _cleanup_free_ char *instance = NULL;
+
+ r = unit_name_to_instance(*name, &instance);
+ if (r < 0)
+ return r;
+
+ r = unit_name_replace_instance(unit_name, instance, &tmp_name);
+ if (r < 0)
+ return r;
+
+ unit_name = tmp_name;
+ }
+
if (path) {
if (arg_full)
- r = unit_file_create_copy(&lp, basename(path), path, &new_path, &tmp_path);
+ r = unit_file_create_copy(&lp, unit_name, path, &new_path, &tmp_path);
else
- r = unit_file_create_new(&lp, basename(path), ".d/override.conf", &new_path, &tmp_path);
+ r = unit_file_create_new(&lp, unit_name, ".d/override.conf", &new_path, &tmp_path);
} else
r = unit_file_create_new(&lp, *name, NULL, &new_path, &tmp_path);
if (r < 0)