chiark / gitweb /
logind: Support logind.conf.d directories in the usual search paths
authorJosh Triplett <josh@joshtriplett.org>
Wed, 29 Oct 2014 12:10:48 +0000 (05:10 -0700)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 27 Nov 2014 00:11:37 +0000 (19:11 -0500)
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.

man/logind.conf.xml
src/login/logind.c
src/login/logind.conf
src/shared/conf-parser.c
src/shared/conf-parser.h

index d37fcba585ee302b780e0ff10d44b166981c4a71..0b35f51eb44a6df18edd5644fa92b3df3cab3f53 100644 (file)
 
         <refnamediv>
                 <refname>logind.conf</refname>
 
         <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>
         </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>
 
         </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>
         </refsect1>
 
         <refsect1>
index 8f00c463399bc951015e98e0856e348d08300224..69b219d89e6a9d9acc6e97d7387c4d412e0d61fb 100644 (file)
@@ -1171,10 +1171,11 @@ int manager_run(Manager *m) {
 static int manager_parse_config_file(Manager *m) {
         assert(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[]) {
 }
 
 int main(int argc, char *argv[]) {
index 4608a2c0e2477a30c0300437fd0ed5edbbb57575..6b1943a2d190186b91ca49e40e387df5fbbeaa84 100644 (file)
@@ -5,6 +5,9 @@
 #  the Free Software Foundation; either version 2.1 of the License, or
 #  (at your option) any later version.
 #
 #  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]
 # See logind.conf(5) for details
 
 [Login]
index ee6de653e13286220202f067485e2e70cdbeea1c..027c49ce3bdee71f3f3fb77d4cd2d789ed654b15 100644 (file)
@@ -27,6 +27,7 @@
 #include <netinet/ether.h>
 
 #include "conf-parser.h"
 #include <netinet/ether.h>
 
 #include "conf-parser.h"
+#include "conf-files.h"
 #include "util.h"
 #include "macro.h"
 #include "strv.h"
 #include "util.h"
 #include "macro.h"
 #include "strv.h"
@@ -430,6 +431,37 @@ int config_parse(const char *unit,
         return 0;
 }
 
         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,                   \
 #define DEFINE_PARSER(type, vartype, conv_func)                         \
         int config_parse_##type(const char *unit,                       \
                                 const char *filename,                   \
index 62f2a01e5e6862294a27a5e64c08fc60401d9ef6..69d32711b7fbfcd94a1df1462571388b44458901 100644 (file)
@@ -92,6 +92,14 @@ int config_parse(const char *unit,
                  bool warn,
                  void *userdata);
 
                  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);
 /* 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);