From e8461023531de98ac6a49eff9d6ffeff6315249c Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Wed, 29 Oct 2014 05:10:48 -0700 Subject: 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. --- src/shared/conf-parser.c | 32 ++++++++++++++++++++++++++++++++ src/shared/conf-parser.h | 8 ++++++++ 2 files changed, 40 insertions(+) (limited to 'src/shared') diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index ee6de653e1..027c49ce3b 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 62f2a01e5e..69d32711b7 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); -- cgit v1.2.3-54-g00ecf