]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/test/test-fileio.c
systemctl: fix silent failure when --root is not found
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 10 Mar 2022 15:47:51 +0000 (16:47 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 29 Mar 2022 14:17:56 +0000 (16:17 +0200)
commit99aad9a2b9e2c06023a2043976fd9395332ff097
tree83f451c5ecbb365e13bcea180f8f6ec9dc729fbb
parent0d11db59825a9deee0b56fdede0602ef1c37c5c5
systemctl: fix silent failure when --root is not found

Some calls to lookup_path_init() were not followed by any log emission.
E.g.:
$ SYSTEMD_LOG_LEVEL=debug systemctl --root=/missing enable unit; echo $?
1

Let's add a helper function and use it in various places.

$ SYSTEMD_LOG_LEVEL=debug build/systemctl --root=/missing enable unit; echo $?
Failed to initialize unit search paths for root directory /missing: No such file or directory
1
$ SYSTEMCTL_SKIP_SYSV=1 build/systemctl --root=/missing enable unit; echo $?
Failed to initialize unit search paths for root directory /missing: No such file or directory
Failed to enable: No such file or directory.
1

The repeated error in the second case is not very nice, but this is a niche
case and I don't think it's worth the trouble to trying to avoid it.
14 files changed:
src/analyze/analyze-unit-files.c
src/analyze/analyze-unit-paths.c
src/basic/env-file.c
src/basic/path-lookup.c
src/basic/path-lookup.h
src/core/manager.c
src/shared/condition.c
src/shared/install.c
src/systemctl/systemctl-edit.c
src/systemctl/systemctl-enable.c
src/systemctl/systemctl-sysv-compat.c
src/sysv-generator/sysv-generator.c
src/test/test-fileio.c
src/test/test-os-util.c