analyze: fix printing config when there is no main config file
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 20 Nov 2021 10:42:31 +0000 (11:42 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 13 Jan 2022 09:57:14 +0000 (10:57 +0100)
commitf4d72d035d2503241dbf0ff0bd445b479ff25dec
tree93cc46dbce8839e3f8d7945cf3cc71dc362c0419
parent12fffc6e53ec25f9998de4b76d289df757a058b7
analyze: fix printing config when there is no main config file

Since 8b8024f1c231c166f5c450905c8fd91d11704ae7 and the follow-up commits, the
main config file may be located in /usr or in other paths. But the code in
analyze.c was still assuming that it must be in /etc. Things mostly worked for
our own config files because we usually install a comments-only file in /etc,
but was not correct in the general case.

This fixes in particular 'systemd-analyze cat-config systemd/zram-generator.conf'.
In Fedora we distribute a config file in zram-generator-defaults.rpm that is in
/usr/lib, and 'cat-config' would refuse to show it because
/etc/systemd/zram-generator.conf does not exist.

The main config file is optional, but let's print an informative message
because this is a slightly unusual case.

The file paths that we printed were missing the root prefix.

(cherry picked from commit 0895e87348e5fc02f50498cad5922eb3eb172323)
(cherry picked from commit 8621f957b6e3a7eed1c5965d332ad1c4c594f26e)
src/shared/pretty-print.c