1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-28 05:57:33 +03:00

analyze-verify: honour $SYSTEMD_UNIT_PATH, allow system paths to be ignored

SYSTEMD_UNIT_PATH=foobar: systemd-analyze verify barbar/unit.service
will load units from barbar/, foobar/, /etc/systemd/system/, etc.

SYSTEMD_UNIT_PATH= systemd-analyze verify barbar/unit.service
will load units only from barbar/, which is useful e.g. when testing
systemd's own units on a system with an older version of systemd installed.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2016-09-25 09:55:26 -04:00 committed by Martin Pitt
parent dd5e7000cb
commit d941ea22e3
2 changed files with 23 additions and 11 deletions

View File

@ -181,14 +181,15 @@
<option>--log-target=</option>, described in <option>--log-target=</option>, described in
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>).</para> <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>).</para>
<para><command>systemd-analyze verify</command> will load unit <para><command>systemd-analyze verify</command> will load unit files and print
files and print warnings if any errors are detected. Files warnings if any errors are detected. Files specified on the command line will be
specified on the command line will be loaded, but also any other loaded, but also any other units referenced by them. The full unit search path is
units referenced by them. This command works by prepending the formed by combining the directories for all command line arguments, and the usual unit
directories for all command line arguments at the beginning of the load paths (variable <varname>$SYSTEMD_UNIT_PATH</varname> is supported, and may be
unit load path, which means that all units files found in those used to replace or augment the compiled in set of unit load paths; see
directories will be used in preference to the unit files found in <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
the standard locations, even if not listed explicitly.</para> All units files present in the directories containing the command line arguments will
be used in preference to the other paths.</para>
<para>If no command is passed, <command>systemd-analyze <para>If no command is passed, <command>systemd-analyze
time</command> is implied.</para> time</command> is implied.</para>

View File

@ -71,6 +71,7 @@ static int prepare_filename(const char *filename, char **ret) {
} }
static int generate_path(char **var, char **filenames) { static int generate_path(char **var, char **filenames) {
const char *old;
char **filename; char **filename;
_cleanup_strv_free_ char **ans = NULL; _cleanup_strv_free_ char **ans = NULL;
@ -90,9 +91,19 @@ static int generate_path(char **var, char **filenames) {
assert_se(strv_uniq(ans)); assert_se(strv_uniq(ans));
r = strv_extend(&ans, ""); /* First, prepend our directories. Second, if some path was specified, use that, and
if (r < 0) * otherwise use the defaults. Any duplicates will be filtered out in path-lookup.c.
return r; * Treat explicit empty path to mean that nothing should be appended.
*/
old = getenv("SYSTEMD_UNIT_PATH");
if (!streq_ptr(old, "")) {
if (!old)
old = ":";
r = strv_extend(&ans, old);
if (r < 0)
return r;
}
*var = strv_join(ans, ":"); *var = strv_join(ans, ":");
if (!*var) if (!*var)