valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

Blame SOURCES/0153-delta-if-prefix-is-specified-only-show-overrides-the.patch

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