From 98199724cb9fdad910e8f4b222d39d9d1e77f1c4 Mon Sep 17 00:00:00 2001 From: Anita Zhang Date: Thu, 14 Jan 2021 00:02:09 -0800 Subject: [PATCH 1/2] systemctl-edit: fix abort in find_paths_to_edit() After 85c5d313b5c92115f5c77663e736bcf21e99f02f, if you, for example, create a drop-in for -.slice without a corresponding -.slice file, you will get the following: # put some valid stuff in /etc/systemd/system/-.slice.d/override.conf [root@image ~]# systemctl daemon-reload [root@image ~]# systemctl edit -- -.slice Assertion 'path' failed at src/systemctl/systemctl-edit.c:425, function find_paths_to_edit(). Aborting. Aborted The aforementioned commit sets the ret_dropin_paths argument for unit_find_paths(). Thus, unit_find_paths() returns 1 in the example above because it finds a relevant drop-in. However find_paths_to_edit() was written to expect 1 only if the unit file itself exists (it does not in this example). To make this behave more like the version of `systemctl edit` prior to this commit, add an additional check so the code enters the "unit file not found" code branch. --- src/systemctl/systemctl-edit.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/systemctl/systemctl-edit.c b/src/systemctl/systemctl-edit.c index f6e8671a38..a67318258e 100644 --- a/src/systemctl/systemctl-edit.c +++ b/src/systemctl/systemctl-edit.c @@ -405,9 +405,7 @@ static int find_paths_to_edit(sd_bus *bus, char **names, char ***paths) { if (r < 0) return r; - if (r == 0) { - assert(!path); - + if (!path) { if (!arg_force) { log_info("Run 'systemctl edit%s --force --full %s' to create a new unit.", arg_scope == UNIT_FILE_GLOBAL ? " --global" : @@ -422,8 +420,6 @@ static int find_paths_to_edit(sd_bus *bus, char **names, char ***paths) { arg_full ? NULL : ".d/override.conf", NULL, &new_path, &tmp_path); } else { - assert(path); - unit_name = basename(path); /* We follow unit aliases, but we need to propagate the instance */ if (unit_name_is_valid(*name, UNIT_NAME_INSTANCE) && From e4d22a9f321e3d7c4a3e3bc1783c5204d79d80e3 Mon Sep 17 00:00:00 2001 From: Anita Zhang Date: Thu, 14 Jan 2021 00:17:41 -0800 Subject: [PATCH 2/2] systemctl-edit: Add missing ret_dropin_paths argument in retry path find_paths_to_edit() makes 2 calls to unit_find_paths(), one of which is a retry client-side. ret_dropin_paths should be passed the same in both cases. --- src/systemctl/systemctl-edit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/systemctl/systemctl-edit.c b/src/systemctl/systemctl-edit.c index a67318258e..4186ec3aea 100644 --- a/src/systemctl/systemctl-edit.c +++ b/src/systemctl/systemctl-edit.c @@ -398,7 +398,7 @@ static int find_paths_to_edit(sd_bus *bus, char **names, char ***paths) { /* If loading of the unit failed server side complete, then the server won't tell us * the unit file path. In that case, find the file client side. */ log_debug_errno(r, "Unit '%s' was not loaded correctly, retrying client-side.", *name); - r = unit_find_paths(bus, *name, &lp, true, &cached_name_map, &cached_id_map, &path, NULL); + r = unit_find_paths(bus, *name, &lp, true, &cached_name_map, &cached_id_map, &path, &unit_paths); } if (r == -ERFKILL) return log_error_errno(r, "Unit '%s' masked, cannot edit.", *name);