conf-parser: generalize config_parse_config_file()
authorDavid Tardon <dtardon@redhat.com>
Fri, 5 Jan 2024 13:30:37 +0000 (14:30 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 11 Jan 2024 04:24:32 +0000 (13:24 +0900)
src/shared/conf-parser.c
src/shared/conf-parser.h

index 1d201528ace4bc50a4256bbb5f27c652a983d219..8eea22353537468fbbb7c0d2e8d7e8b99970409f 100644 (file)
@@ -598,10 +598,11 @@ static int config_parse_many_files(
         return 0;
 }
 
-/* Parse one main config file located in /etc/systemd and its drop-ins, which is what all systemd daemons
+/* Parse one main config file located in /etc/$pkgdir and its drop-ins, which is what all systemd daemons
  * do. */
-int config_parse_config_file(
+int config_parse_config_file_full(
                 const char *conf_file,
+                const char *pkgdir,
                 const char *sections,
                 ConfigItemLookup lookup,
                 const void *table,
@@ -613,6 +614,7 @@ int config_parse_config_file(
         int r;
 
         assert(conf_file);
+        assert(pkgdir);
 
         /* build the dropin dir list */
         dropin_dirs = new0(char*, strv_length(conf_paths) + 1);
@@ -626,7 +628,7 @@ int config_parse_config_file(
         STRV_FOREACH(p, conf_paths) {
                 char *d;
 
-                d = strjoin(*p, "systemd/", conf_file, ".d");
+                d = strjoin(*p, pkgdir, "/", conf_file, ".d");
                 if (!d) {
                         if (flags & CONFIG_PARSE_WARN)
                                 return log_oom();
@@ -640,7 +642,7 @@ int config_parse_config_file(
         if (r < 0)
                 return r;
 
-        const char *sysconf_file = strjoina(PKGSYSCONFDIR, "/", conf_file);
+        const char *sysconf_file = strjoina(SYSCONF_DIR, "/", pkgdir, "/", conf_file);
 
         return config_parse_many_files(STRV_MAKE_CONST(sysconf_file), dropins,
                                        sections, lookup, table, flags, userdata, NULL);
index a1768cd9198e9c511f1075bf84c4a6ebd2431b5c..4e0054de5e2d43bd8b330a6da278ca7caef6498f 100644 (file)
@@ -93,14 +93,25 @@ int config_parse(
                 void *userdata,
                 struct stat *ret_stat);     /* possibly NULL */
 
-int config_parse_config_file(
+int config_parse_config_file_full(
                 const char *conf_file,
+                const char *pkgdir,
                 const char *sections,       /* nulstr */
                 ConfigItemLookup lookup,
                 const void *table,
                 ConfigParseFlags flags,
                 void *userdata);
 
+static inline int config_parse_config_file(
+                const char *conf_file,
+                const char *sections,       /* nulstr */
+                ConfigItemLookup lookup,
+                const void *table,
+                ConfigParseFlags flags,
+                void *userdata) {
+        return config_parse_config_file_full(conf_file, "systemd", sections, lookup, table, flags, userdata);
+}
+
 int config_parse_many(
                 const char* const* conf_files,  /* possibly empty */
                 const char* const* conf_file_dirs,