|
|
65878a |
From 13fb7479365d958e76b149fe5615be74f519f03a Mon Sep 17 00:00:00 2001
|
|
|
65878a |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
65878a |
Date: Sun, 22 Dec 2013 22:53:23 -0500
|
|
|
65878a |
Subject: [PATCH] delta: if prefix is specified, only show overrides there
|
|
|
65878a |
|
|
|
65878a |
systemd-delta /run/systemd/system will show all unit overrides
|
|
|
65878a |
in /run, etc.
|
|
|
65878a |
---
|
|
|
65878a |
man/systemd-delta.xml | 80 +++++++++++++++++++++++++++++++++++++++++----------
|
|
|
65878a |
src/delta/delta.c | 71 ++++++++++++++++++++++++++++-----------------
|
|
|
65878a |
2 files changed, 109 insertions(+), 42 deletions(-)
|
|
|
65878a |
|
|
|
65878a |
diff --git a/man/systemd-delta.xml b/man/systemd-delta.xml
|
|
|
65878a |
index 413ebd8..4d3ab78 100644
|
|
|
65878a |
--- a/man/systemd-delta.xml
|
|
|
65878a |
+++ b/man/systemd-delta.xml
|
|
|
65878a |
@@ -49,7 +49,9 @@
|
|
|
65878a |
|
|
|
65878a |
<refsynopsisdiv>
|
|
|
65878a |
<cmdsynopsis>
|
|
|
65878a |
- <command>systemd-delta <arg choice="opt" rep="repeat">OPTIONS</arg> <arg choice="opt" rep="repeat">SUFFIX</arg></command>
|
|
|
65878a |
+ <command>systemd-delta</command>
|
|
|
65878a |
+ <arg choice="opt" rep="repeat">OPTIONS</arg>
|
|
|
65878a |
+ <arg choice="opt" rep="repeat"><replaceable>PREFIX</replaceable><optional>/<replaceable>SUFFIX</replaceable></optional>|<replaceable>SUFFIX</replaceable></arg>
|
|
|
65878a |
</cmdsynopsis>
|
|
|
65878a |
</refsynopsisdiv>
|
|
|
65878a |
|
|
|
65878a |
@@ -57,18 +59,46 @@
|
|
|
65878a |
<title>Description</title>
|
|
|
65878a |
|
|
|
65878a |
<para><command>systemd-delta</command> may be used to
|
|
|
65878a |
- identify and compare configuration files in
|
|
|
65878a |
- <filename>/etc</filename> that override default
|
|
|
65878a |
- counterparts in <filename>/usr</filename>. The command
|
|
|
65878a |
- line argument can be one or more name of a subdirectories of
|
|
|
65878a |
- <filename>/etc</filename> or
|
|
|
65878a |
- <filename>/usr/lib</filename> to compare, such as
|
|
|
65878a |
- <filename>tmpfiles.d</filename>, <filename>sysctl.d</filename> or
|
|
|
65878a |
- <filename>systemd/system</filename>.</para>
|
|
|
65878a |
-
|
|
|
65878a |
- <para>When no argument is specified a number of
|
|
|
65878a |
- well-known subdirectories are searched for overridden
|
|
|
65878a |
- files.</para>
|
|
|
65878a |
+ identify and compare configuration files that override
|
|
|
65878a |
+ other configuration files. Files in
|
|
|
65878a |
+ <filename>/etc</filename> have highest priority, files
|
|
|
65878a |
+ in <filename>/run</filename> have the second highest
|
|
|
65878a |
+ priority, ..., files in <filename>/lib</filename> have
|
|
|
65878a |
+ lowest priority. Files in a directory with higher
|
|
|
65878a |
+ priority override files with the same name in
|
|
|
65878a |
+ directories of lower priority. In addition, certain
|
|
|
65878a |
+ configuration files can have <literal>.d</literal>
|
|
|
65878a |
+ directories which contain "drop-in" files with
|
|
|
65878a |
+ configuration snippets which augment the main
|
|
|
65878a |
+ configuration file. "Drop-in" files can be overriden
|
|
|
65878a |
+ in the same way by placing files with the same name in
|
|
|
65878a |
+ a directory of higher priority (except that in case of
|
|
|
65878a |
+ "drop-in" files, both the "drop-in" file name and the
|
|
|
65878a |
+ name of the containing directory, which corresponds to
|
|
|
65878a |
+ the name of the main configuration file, must match).
|
|
|
65878a |
+ For a fuller explanation, see
|
|
|
65878a |
+ <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
|
|
|
65878a |
+ </para>
|
|
|
65878a |
+
|
|
|
65878a |
+ <para>The command line argument will be split into a
|
|
|
65878a |
+ prefix and a suffix. Either is optional. The prefix
|
|
|
65878a |
+ must be one of the directories containing
|
|
|
65878a |
+ configuration files (<filename>/etc</filename>,
|
|
|
65878a |
+ <filename>/run</filename>,
|
|
|
65878a |
+ <filename>/usr/lib</filename>, ...). If it is given,
|
|
|
65878a |
+ only overriding files contained in this directory will
|
|
|
65878a |
+ be shown. Otherwise, all overriding files will be
|
|
|
65878a |
+ shown. The suffix must be a name of a subdirectory
|
|
|
65878a |
+ containing configuration files like
|
|
|
65878a |
+ <filename>tmpfiles.d</filename>,
|
|
|
65878a |
+ <filename>sysctl.d</filename> or
|
|
|
65878a |
+ <filename>systemd/system</filename>. If it is given,
|
|
|
65878a |
+ only configuration files in this subdirectory (across
|
|
|
65878a |
+ all configuration paths) will be analyzed. Otherwise,
|
|
|
65878a |
+ all configuration files will be analyzed. If the
|
|
|
65878a |
+ commandline argument is not given at all, all
|
|
|
65878a |
+ configuration files will be analyzed. See below for
|
|
|
65878a |
+ some examples.</para>
|
|
|
65878a |
</refsect1>
|
|
|
65878a |
|
|
|
65878a |
<refsect1>
|
|
|
65878a |
@@ -168,9 +198,28 @@
|
|
|
65878a |
</varlistentry>
|
|
|
65878a |
|
|
|
65878a |
</variablelist>
|
|
|
65878a |
-
|
|
|
65878a |
</refsect1>
|
|
|
65878a |
|
|
|
65878a |
+ <refsect1>
|
|
|
65878a |
+ <title>Examples</title>
|
|
|
65878a |
+
|
|
|
65878a |
+ <para>To see all local configuration:</para>
|
|
|
65878a |
+ <programlisting>systemd-delta
|
|
|
65878a |
+ </programlisting>
|
|
|
65878a |
+
|
|
|
65878a |
+ <para>To see all runtime configuration:</para>
|
|
|
65878a |
+ <programlisting>systemd-delta /run
|
|
|
65878a |
+ </programlisting>
|
|
|
65878a |
+
|
|
|
65878a |
+ <para>To see all system unit configuration changes:</para>
|
|
|
65878a |
+ <programlisting>systemd-delta systemd/system
|
|
|
65878a |
+ </programlisting>
|
|
|
65878a |
+
|
|
|
65878a |
+ <para>To see all runtime "drop-in" changes for system units:</para>
|
|
|
65878a |
+ <programlisting>systemd-delta --type=extended /run/systemd/system
|
|
|
65878a |
+ </programlisting>
|
|
|
65878a |
+ </refsect1>
|
|
|
65878a |
+
|
|
|
65878a |
<refsect1>
|
|
|
65878a |
<title>Exit status</title>
|
|
|
65878a |
|
|
|
65878a |
@@ -181,7 +230,8 @@
|
|
|
65878a |
<refsect1>
|
|
|
65878a |
<title>See Also</title>
|
|
|
65878a |
<para>
|
|
|
65878a |
- <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>
|
|
|
65878a |
+ <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
|
|
|
65878a |
+ <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
|
|
|
65878a |
</para>
|
|
|
65878a |
</refsect1>
|
|
|
65878a |
|
|
|
65878a |
diff --git a/src/delta/delta.c b/src/delta/delta.c
|
|
|
65878a |
index 06c7431..a8dd57e 100644
|
|
|
65878a |
--- a/src/delta/delta.c
|
|
|
65878a |
+++ b/src/delta/delta.c
|
|
|
65878a |
@@ -4,6 +4,7 @@
|
|
|
65878a |
This file is part of systemd.
|
|
|
65878a |
|
|
|
65878a |
Copyright 2012 Lennart Poettering
|
|
|
65878a |
+ Copyright 2013 Zbigniew Jędrzejewski-Szmek
|
|
|
65878a |
|
|
|
65878a |
systemd is free software; you can redistribute it and/or modify it
|
|
|
65878a |
under the terms of the GNU Lesser General Public License as published by
|
|
|
65878a |
@@ -348,7 +349,7 @@ static int enumerate_dir(Hashmap *top, Hashmap *bottom, Hashmap *drops, const ch
|
|
|
65878a |
}
|
|
|
65878a |
}
|
|
|
65878a |
|
|
|
65878a |
-static int process_suffix(const char *suffix) {
|
|
|
65878a |
+static int process_suffix(const char *suffix, const char *onlyprefix) {
|
|
|
65878a |
const char *p;
|
|
|
65878a |
char *f;
|
|
|
65878a |
Hashmap *top, *bottom, *drops;
|
|
|
65878a |
@@ -393,20 +394,23 @@ static int process_suffix(const char *suffix) {
|
|
|
65878a |
o = hashmap_get(bottom, key);
|
|
|
65878a |
assert(o);
|
|
|
65878a |
|
|
|
65878a |
- if (path_equal(o, f))
|
|
|
65878a |
- notify_override_unchanged(f);
|
|
|
65878a |
- else {
|
|
|
65878a |
- k = found_override(f, o);
|
|
|
65878a |
- if (k < 0)
|
|
|
65878a |
- r = k;
|
|
|
65878a |
- else
|
|
|
65878a |
- n_found += k;
|
|
|
65878a |
+ if (!onlyprefix || startswith(o, onlyprefix)) {
|
|
|
65878a |
+ if (path_equal(o, f)) {
|
|
|
65878a |
+ notify_override_unchanged(f);
|
|
|
65878a |
+ } else {
|
|
|
65878a |
+ k = found_override(f, o);
|
|
|
65878a |
+ if (k < 0)
|
|
|
65878a |
+ r = k;
|
|
|
65878a |
+ else
|
|
|
65878a |
+ n_found += k;
|
|
|
65878a |
+ }
|
|
|
65878a |
}
|
|
|
65878a |
|
|
|
65878a |
h = hashmap_get(drops, key);
|
|
|
65878a |
if (h)
|
|
|
65878a |
HASHMAP_FOREACH(o, h, j)
|
|
|
65878a |
- n_found += notify_override_extended(f, o);
|
|
|
65878a |
+ if (!onlyprefix || startswith(o, onlyprefix))
|
|
|
65878a |
+ n_found += notify_override_extended(f, o);
|
|
|
65878a |
}
|
|
|
65878a |
|
|
|
65878a |
finish:
|
|
|
65878a |
@@ -425,24 +429,41 @@ finish:
|
|
|
65878a |
return r < 0 ? r : n_found;
|
|
|
65878a |
}
|
|
|
65878a |
|
|
|
65878a |
-static int process_suffix_chop(const char *suffix) {
|
|
|
65878a |
+static int process_suffixes(const char *onlyprefix) {
|
|
|
65878a |
+ const char *n;
|
|
|
65878a |
+ int n_found = 0, r;
|
|
|
65878a |
+
|
|
|
65878a |
+ NULSTR_FOREACH(n, suffixes) {
|
|
|
65878a |
+ r = process_suffix(n, onlyprefix);
|
|
|
65878a |
+ if (r < 0)
|
|
|
65878a |
+ return r;
|
|
|
65878a |
+ else
|
|
|
65878a |
+ n_found += r;
|
|
|
65878a |
+ }
|
|
|
65878a |
+ return n_found;
|
|
|
65878a |
+}
|
|
|
65878a |
+
|
|
|
65878a |
+static int process_suffix_chop(const char *arg) {
|
|
|
65878a |
const char *p;
|
|
|
65878a |
|
|
|
65878a |
- assert(suffix);
|
|
|
65878a |
+ assert(arg);
|
|
|
65878a |
|
|
|
65878a |
- if (!path_is_absolute(suffix))
|
|
|
65878a |
- return process_suffix(suffix);
|
|
|
65878a |
+ if (!path_is_absolute(arg))
|
|
|
65878a |
+ return process_suffix(arg, NULL);
|
|
|
65878a |
|
|
|
65878a |
/* Strip prefix from the suffix */
|
|
|
65878a |
NULSTR_FOREACH(p, prefixes) {
|
|
|
65878a |
- if (startswith(suffix, p)) {
|
|
|
65878a |
- suffix += strlen(p);
|
|
|
65878a |
+ const char *suffix = startswith(arg, p);
|
|
|
65878a |
+ if (suffix) {
|
|
|
65878a |
suffix += strspn(suffix, "/");
|
|
|
65878a |
- return process_suffix(suffix);
|
|
|
65878a |
+ if (*suffix)
|
|
|
65878a |
+ return process_suffix(suffix, NULL);
|
|
|
65878a |
+ else
|
|
|
65878a |
+ return process_suffixes(arg);
|
|
|
65878a |
}
|
|
|
65878a |
}
|
|
|
65878a |
|
|
|
65878a |
- log_error("Invalid suffix specification %s.", suffix);
|
|
|
65878a |
+ log_error("Invalid suffix specification %s.", arg);
|
|
|
65878a |
return -EINVAL;
|
|
|
65878a |
}
|
|
|
65878a |
|
|
|
65878a |
@@ -596,15 +617,11 @@ int main(int argc, char *argv[]) {
|
|
|
65878a |
}
|
|
|
65878a |
|
|
|
65878a |
} else {
|
|
|
65878a |
- const char *n;
|
|
|
65878a |
-
|
|
|
65878a |
- NULSTR_FOREACH(n, suffixes) {
|
|
|
65878a |
- k = process_suffix(n);
|
|
|
65878a |
- if (k < 0)
|
|
|
65878a |
- r = k;
|
|
|
65878a |
- else
|
|
|
65878a |
- n_found += k;
|
|
|
65878a |
- }
|
|
|
65878a |
+ k = process_suffixes(NULL);
|
|
|
65878a |
+ if (k < 0)
|
|
|
65878a |
+ r = k;
|
|
|
65878a |
+ else
|
|
|
65878a |
+ n_found += k;
|
|
|
65878a |
}
|
|
|
65878a |
|
|
|
65878a |
if (r >= 0)
|