[systemd-commits] 2 commits - man/logind.conf.xml src/binfmt src/login src/modules-load src/shared src/sysctl src/sysusers src/tmpfiles

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Wed Nov 26 16:42:21 PST 2014


 man/logind.conf.xml             |   29 ++++++++++++++++++++++++++---
 src/binfmt/binfmt.c             |   10 +---------
 src/login/logind.c              |    9 +++++----
 src/login/logind.conf           |    3 +++
 src/modules-load/modules-load.c |   10 +---------
 src/shared/conf-parser.c        |   32 ++++++++++++++++++++++++++++++++
 src/shared/conf-parser.h        |    8 ++++++++
 src/shared/macro.h              |   15 +++++++++++++++
 src/sysctl/sysctl.c             |   10 +---------
 src/sysusers/sysusers.c         |   10 +---------
 src/tmpfiles/tmpfiles.c         |   10 +---------
 11 files changed, 94 insertions(+), 52 deletions(-)

New commits:
commit e8461023531de98ac6a49eff9d6ffeff6315249c
Author: Josh Triplett <josh at joshtriplett.org>
Date:   Wed Oct 29 05:10:48 2014 -0700

    logind: Support logind.conf.d directories in the usual search paths
    
    This makes it possible to drop in logind configuration snippets from a
    package or other configuration management mechanism.
    
    Add documentation to the header of /etc/logind.conf pointing the user at
    /etc/logind.conf.d/*.conf.
    
    Introduce a new helper, conf_parse_many, to parse configuration files in
    a search path.

diff --git a/man/logind.conf.xml b/man/logind.conf.xml
index d37fcba..0b35f51 100644
--- a/man/logind.conf.xml
+++ b/man/logind.conf.xml
@@ -44,18 +44,41 @@
 
         <refnamediv>
                 <refname>logind.conf</refname>
-                <refpurpose>Login manager configuration file</refpurpose>
+                <refpurpose>Login manager configuration files</refpurpose>
         </refnamediv>
 
         <refsynopsisdiv>
                 <para><filename>/etc/systemd/logind.conf</filename></para>
+                <para><filename>/etc/systemd/logind.conf.d/*.conf</filename></para>
+                <para><filename>/run/systemd/logind.conf.d/*.conf</filename></para>
+                <para><filename>/usr/lib/systemd/logind.conf.d/*.conf</filename></para>
         </refsynopsisdiv>
 
         <refsect1>
                 <title>Description</title>
 
-                <para>This file configures various parameters of the systemd login manager, <citerefentry><refentrytitle>systemd-logind.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para>
-
+                <para>These files configure various parameters of the systemd login manager, <citerefentry><refentrytitle>systemd-logind.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para>
+
+                <para>Each configuration file shall be named in the style of
+                <filename><replaceable>filename</replaceable>.conf</filename>.
+                Files in <filename>/etc/</filename> override files with the
+                same name in <filename>/usr/lib/</filename> and
+                <filename>/run/</filename>.  Files in
+                <filename>/run/</filename> override files with the same name in
+                <filename>/usr/lib/</filename>. Packages should install their
+                configuration files in <filename>/usr/lib/</filename>. Files in
+                <filename>/etc/</filename> are reserved for the local
+                administrator, who may use this logic to override the
+                configuration files installed by vendor packages. All
+                configuration files are sorted by their filename in
+                lexicographic order, regardless of which of the directories
+                they reside in. If multiple files specify the same option, the
+                entry in the file with the lexicographically latest name will
+                be applied; entries in any <filename>logind.conf.d</filename>
+                file override entries in
+                <filename>/etc/systemd/logind.conf</filename>. It is
+                recommended to prefix all filenames with a two-digit number and
+                a dash, to simplify the ordering of the files.</para>
         </refsect1>
 
         <refsect1>
diff --git a/src/login/logind.c b/src/login/logind.c
index 8f00c46..69b219d 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -1171,10 +1171,11 @@ int manager_run(Manager *m) {
 static int manager_parse_config_file(Manager *m) {
         assert(m);
 
-        return config_parse(NULL, "/etc/systemd/logind.conf", NULL,
-                            "Login\0",
-                            config_item_perf_lookup, logind_gperf_lookup,
-                            false, false, true, m);
+        return config_parse_many("/etc/systemd/logind.conf",
+                                 CONF_DIRS_NULSTR("systemd/logind.conf"),
+                                 "Login\0",
+                                 config_item_perf_lookup, logind_gperf_lookup,
+                                 false, m);
 }
 
 int main(int argc, char *argv[]) {
diff --git a/src/login/logind.conf b/src/login/logind.conf
index 4608a2c..6b1943a 100644
--- a/src/login/logind.conf
+++ b/src/login/logind.conf
@@ -5,6 +5,9 @@
 #  the Free Software Foundation; either version 2.1 of the License, or
 #  (at your option) any later version.
 #
+# You can override the directives in this file by creating files in
+# /etc/systemd/logind.conf.d/*.conf.
+#
 # See logind.conf(5) for details
 
 [Login]
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index ee6de65..027c49c 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -27,6 +27,7 @@
 #include <netinet/ether.h>
 
 #include "conf-parser.h"
+#include "conf-files.h"
 #include "util.h"
 #include "macro.h"
 #include "strv.h"
@@ -430,6 +431,37 @@ int config_parse(const char *unit,
         return 0;
 }
 
+/* Parse each config file in the specified directories. */
+int config_parse_many(const char *conf_file,
+                      const char *conf_file_dirs,
+                      const char *sections,
+                      ConfigItemLookup lookup,
+                      const void *table,
+                      bool relaxed,
+                      void *userdata) {
+        _cleanup_strv_free_ char **files = NULL;
+        char **fn;
+        int r;
+
+        r = conf_files_list_nulstr(&files, ".conf", NULL, conf_file_dirs);
+        if (r < 0)
+                return r;
+
+        if (conf_file) {
+                r = config_parse(NULL, conf_file, NULL, sections, lookup, table, relaxed, false, true, userdata);
+                if (r < 0)
+                        return r;
+        }
+
+        STRV_FOREACH(fn, files) {
+                r = config_parse(NULL, *fn, NULL, sections, lookup, table, relaxed, false, true, userdata);
+                if (r < 0)
+                        return r;
+        }
+
+        return 0;
+}
+
 #define DEFINE_PARSER(type, vartype, conv_func)                         \
         int config_parse_##type(const char *unit,                       \
                                 const char *filename,                   \
diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h
index 62f2a01..69d3271 100644
--- a/src/shared/conf-parser.h
+++ b/src/shared/conf-parser.h
@@ -92,6 +92,14 @@ int config_parse(const char *unit,
                  bool warn,
                  void *userdata);
 
+int config_parse_many(const char *conf_file,      /* possibly NULL */
+                      const char *conf_file_dirs, /* nulstr */
+                      const char *sections,       /* nulstr */
+                      ConfigItemLookup lookup,
+                      const void *table,
+                      bool relaxed,
+                      void *userdata);
+
 /* Generic parsers */
 int config_parse_int(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_unsigned(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);

commit 7f0a55d4325f7df91f91b3b818f61f97d78df14a
Author: Josh Triplett <josh at joshtriplett.org>
Date:   Wed Oct 29 05:02:56 2014 -0700

    Introduce CONF_DIRS_NULSTR helper to define standard conf dirs
    
    Several different systemd tools define a nulstr containing a standard
    series of configuration file directories, in /etc, /run, /usr/local/lib,
    /usr/lib, and (#ifdef HAVE_SPLIT_USR) /lib.  Factor that logic out into
    a new helper macro, CONF_DIRS_NULSTR.

diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c
index c1c1522..0a15faf 100644
--- a/src/binfmt/binfmt.c
+++ b/src/binfmt/binfmt.c
@@ -36,15 +36,7 @@
 #include "fileio.h"
 #include "build.h"
 
-static const char conf_file_dirs[] =
-        "/etc/binfmt.d\0"
-        "/run/binfmt.d\0"
-        "/usr/local/lib/binfmt.d\0"
-        "/usr/lib/binfmt.d\0"
-#ifdef HAVE_SPLIT_USR
-        "/lib/binfmt.d\0"
-#endif
-        ;
+static const char conf_file_dirs[] = CONF_DIRS_NULSTR("binfmt");
 
 static int delete_rule(const char *rule) {
         _cleanup_free_ char *x = NULL, *fn = NULL;
diff --git a/src/modules-load/modules-load.c b/src/modules-load/modules-load.c
index 08de5e0..c676fd1 100644
--- a/src/modules-load/modules-load.c
+++ b/src/modules-load/modules-load.c
@@ -38,15 +38,7 @@
 
 static char **arg_proc_cmdline_modules = NULL;
 
-static const char conf_file_dirs[] =
-        "/etc/modules-load.d\0"
-        "/run/modules-load.d\0"
-        "/usr/local/lib/modules-load.d\0"
-        "/usr/lib/modules-load.d\0"
-#ifdef HAVE_SPLIT_USR
-        "/lib/modules-load.d\0"
-#endif
-        ;
+static const char conf_file_dirs[] = CONF_DIRS_NULSTR("modules-load");
 
 static void systemd_kmod_log(void *data, int priority, const char *file, int line,
                              const char *fn, const char *format, va_list args) {
diff --git a/src/shared/macro.h b/src/shared/macro.h
index 9ee332c..6d4712c 100644
--- a/src/shared/macro.h
+++ b/src/shared/macro.h
@@ -384,6 +384,21 @@ do {                                                                    \
                 _found;                                                 \
         })
 
+/* Return a nulstr for a standard cascade of configuration directories,
+ * suitable to pass to conf_files_list_nulstr or config_parse_many. */
+#define CONF_DIRS_NULSTR(n) \
+        "/etc/" n ".d\0" \
+        "/run/" n ".d\0" \
+        "/usr/local/lib/" n ".d\0" \
+        "/usr/lib/" n ".d\0" \
+        CONF_DIR_SPLIT_USR(n)
+
+#ifdef HAVE_SPLIT_USR
+#define CONF_DIR_SPLIT_USR(n) "/lib/" n ".d\0"
+#else
+#define CONF_DIR_SPLIT_USR(n)
+#endif
+
 /* Define C11 thread_local attribute even on older gcc compiler
  * version */
 #ifndef thread_local
diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c
index 809e59b..edebe50 100644
--- a/src/sysctl/sysctl.c
+++ b/src/sysctl/sysctl.c
@@ -38,15 +38,7 @@
 
 static char **arg_prefixes = NULL;
 
-static const char conf_file_dirs[] =
-        "/etc/sysctl.d\0"
-        "/run/sysctl.d\0"
-        "/usr/local/lib/sysctl.d\0"
-        "/usr/lib/sysctl.d\0"
-#ifdef HAVE_SPLIT_USR
-        "/lib/sysctl.d\0"
-#endif
-        ;
+static const char conf_file_dirs[] = CONF_DIRS_NULSTR("sysctl");
 
 static char* normalize_sysctl(char *s) {
         char *n;
diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c
index 04e973a..7820e84 100644
--- a/src/sysusers/sysusers.c
+++ b/src/sysusers/sysusers.c
@@ -67,15 +67,7 @@ typedef struct Item {
 
 static char *arg_root = NULL;
 
-static const char conf_file_dirs[] =
-        "/etc/sysusers.d\0"
-        "/run/sysusers.d\0"
-        "/usr/local/lib/sysusers.d\0"
-        "/usr/lib/sysusers.d\0"
-#ifdef HAVE_SPLIT_USR
-        "/lib/sysusers.d\0"
-#endif
-        ;
+static const char conf_file_dirs[] = CONF_DIRS_NULSTR("sysusers");
 
 static Hashmap *users = NULL, *groups = NULL;
 static Hashmap *todo_uids = NULL, *todo_gids = NULL;
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 1e4675f..23fd6ca 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -117,15 +117,7 @@ static char **arg_include_prefixes = NULL;
 static char **arg_exclude_prefixes = NULL;
 static char *arg_root = NULL;
 
-static const char conf_file_dirs[] =
-        "/etc/tmpfiles.d\0"
-        "/run/tmpfiles.d\0"
-        "/usr/local/lib/tmpfiles.d\0"
-        "/usr/lib/tmpfiles.d\0"
-#ifdef HAVE_SPLIT_USR
-        "/lib/tmpfiles.d\0"
-#endif
-        ;
+static const char conf_file_dirs[] = CONF_DIRS_NULSTR("tmpfiles");
 
 #define MAX_DEPTH 256
 



More information about the systemd-commits mailing list