systemctl-edit: fix abort in find_paths_to_edit()
authorAnita Zhang <the.anitazha@gmail.com>
Thu, 14 Jan 2021 08:02:09 +0000 (00:02 -0800)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 2 Feb 2021 13:52:53 +0000 (14:52 +0100)
commit71630f118709c14c852dd362fadb738982e80cf9
tree9086d84d21e9487be824297c9e2eade587f6ac97
parente12b4112a85cb8a0fde73e7d07664a33afeff1e3
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.

(cherry picked from commit 98199724cb9fdad910e8f4b222d39d9d1e77f1c4)
src/systemctl/systemctl-edit.c