[systemd-devel] [PATCH] logind: Support /etc/systemd/logind.conf.d/*.conf

Josh Triplett josh at joshtriplett.org
Thu Oct 16 03:27:21 PDT 2014


This makes it possible to drop in configuration file snippets from a
package or other configuration management mechanism.
---
 man/logind.conf.xml      |  4 +++-
 src/login/logind.c       | 21 +++++++++++++++++----
 src/shared/conf-parser.c | 19 +++++++++++++++++++
 src/shared/conf-parser.h |  7 +++++++
 4 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/man/logind.conf.xml b/man/logind.conf.xml
index 8ba9523..836f307 100644
--- a/man/logind.conf.xml
+++ b/man/logind.conf.xml
@@ -44,17 +44,19 @@
 
         <refnamediv>
                 <refname>logind.conf</refname>
+                <refname>logind.conf.d</refname>
                 <refpurpose>Login manager configuration file</refpurpose>
         </refnamediv>
 
         <refsynopsisdiv>
                 <para><filename>/etc/systemd/logind.conf</filename></para>
+                <para><filename>/etc/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 configures various parameters of the systemd login manager, <citerefentry><refentrytitle>systemd-logind.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para>
 
         </refsect1>
 
diff --git a/src/login/logind.c b/src/login/logind.c
index 8f00c46..1feb251 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -29,6 +29,7 @@
 
 #include "sd-daemon.h"
 #include "strv.h"
+#include "conf-files.h"
 #include "conf-parser.h"
 #include "mkdir.h"
 #include "bus-util.h"
@@ -1169,12 +1170,24 @@ int manager_run(Manager *m) {
 }
 
 static int manager_parse_config_file(Manager *m) {
+        _cleanup_strv_free_ char **filenames = NULL;
+        int r;
+
         assert(m);
 
-        return config_parse(NULL, "/etc/systemd/logind.conf", NULL,
-                            "Login\0",
-                            config_item_perf_lookup, logind_gperf_lookup,
-                            false, false, true, m);
+        r = conf_files_list(&filenames, ".conf", NULL, "/etc/systemd/logind.conf.d", NULL);
+        if (r < 0)
+                return r;
+
+        r = config_parse(NULL, "/etc/systemd/logind.conf", NULL, "Login\0",
+                         config_item_perf_lookup, logind_gperf_lookup,
+                         false, false, true, m);
+        if (r < 0)
+                return r;
+
+        return config_parse_many(filenames, "Login\0",
+                                 config_item_perf_lookup, logind_gperf_lookup,
+                                 false, m);
 }
 
 int main(int argc, char *argv[]) {
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index ee6de65..54bd642 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -430,6 +430,25 @@ int config_parse(const char *unit,
         return 0;
 }
 
+/* Parse each config file, if it exists. */
+int config_parse_many(char **filenames,
+                      const char *sections,
+                      ConfigItemLookup lookup,
+                      const void *table,
+                      bool relaxed,
+                      void *userdata) {
+        char **fn;
+        int r;
+
+        STRV_FOREACH(fn, filenames) {
+                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..37eee55 100644
--- a/src/shared/conf-parser.h
+++ b/src/shared/conf-parser.h
@@ -92,6 +92,13 @@ int config_parse(const char *unit,
                  bool warn,
                  void *userdata);
 
+int config_parse_many(char **filenames,
+                      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);
-- 
2.1.1



More information about the systemd-devel mailing list