dryang / rpms / systemd

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