From e8461023531de98ac6a49eff9d6ffeff6315249c Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Wed, 29 Oct 2014 05:10:48 -0700 Subject: [PATCH] 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. --- man/logind.conf.xml | 29 ++++++++++++++++++++++++++--- src/login/logind.c | 9 +++++---- src/login/logind.conf | 3 +++ src/shared/conf-parser.c | 32 ++++++++++++++++++++++++++++++++ src/shared/conf-parser.h | 8 ++++++++ 5 files changed, 74 insertions(+), 7 deletions(-) diff --git a/man/logind.conf.xml b/man/logind.conf.xml index d37fcba58..0b35f51eb 100644 --- a/man/logind.conf.xml +++ b/man/logind.conf.xml @@ -44,18 +44,41 @@ logind.conf - Login manager configuration file + Login manager configuration files /etc/systemd/logind.conf + /etc/systemd/logind.conf.d/*.conf + /run/systemd/logind.conf.d/*.conf + /usr/lib/systemd/logind.conf.d/*.conf Description - This file configures various parameters of the systemd login manager, systemd-logind.service8. - + These files configure various parameters of the systemd login manager, systemd-logind.service8. + + Each configuration file shall be named in the style of + filename.conf. + Files in /etc/ override files with the + same name in /usr/lib/ and + /run/. Files in + /run/ override files with the same name in + /usr/lib/. Packages should install their + configuration files in /usr/lib/. Files in + /etc/ 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 logind.conf.d + file override entries in + /etc/systemd/logind.conf. It is + recommended to prefix all filenames with a two-digit number and + a dash, to simplify the ordering of the files. diff --git a/src/login/logind.c b/src/login/logind.c index 8f00c4633..69b219d89 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 4608a2c0e..6b1943a2d 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 ee6de653e..027c49ce3 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -27,6 +27,7 @@ #include #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 62f2a01e5..69d32711b 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); -- 2.30.2