From: Zbigniew Jędrzejewski-Szmek Date: Mon, 5 Feb 2018 13:53:11 +0000 (+0100) Subject: tmpfiles: allow admin/runtime overrides to runtime config X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=85ab74b1f848b3754eab1dd0d85ff3d9baec44b6;p=elogind.git tmpfiles: allow admin/runtime overrides to runtime config This is very similar to d16a1c1bb6. For tmpfiles this is much less useful compared to sysusers, but let's add this anyway for consistency. --- diff --git a/src/basic/conf-files.c b/src/basic/conf-files.c index 08ede2c76..8b4129e1c 100644 --- a/src/basic/conf-files.c +++ b/src/basic/conf-files.c @@ -154,7 +154,7 @@ static int conf_files_list_strv_internal(char ***strv, const char *suffix, const return 0; } -int conf_files_insert(char ***strv, const char *root, const char *dirs, const char *path) { +int conf_files_insert(char ***strv, const char *root, char **dirs, const char *path) { /* Insert a path into strv, at the place honouring the usual sorting rules: * - we first compare by the basename * - and then we compare by dirname, allowing just one file with the given @@ -174,22 +174,22 @@ int conf_files_insert(char ***strv, const char *root, const char *dirs, const ch c = base_cmp(*strv + i, &path); if (c == 0) { - const char *dir; + char **dir; /* Oh, we found our spot and it already contains something. */ - NULSTR_FOREACH(dir, dirs) { + STRV_FOREACH(dir, dirs) { char *p1, *p2; p1 = path_startswith((*strv)[i], root); if (p1) - /* Skip "/" in dir, because p1 is without "/" too */ - p1 = path_startswith(p1, dir + 1); + /* Skip "/" in *dir, because p1 is without "/" too */ + p1 = path_startswith(p1, *dir + 1); if (p1) /* Existing entry with higher priority * or same priority, no need to do anything. */ return 0; - p2 = path_startswith(path, dir); + p2 = path_startswith(path, *dir); if (p2) { /* Our new entry has higher priority */ t = path_join(root, path, NULL); @@ -218,6 +218,18 @@ int conf_files_insert(char ***strv, const char *root, const char *dirs, const ch return r; } +int conf_files_insert_nulstr(char ***strv, const char *root, const char *dirs, const char *path) { + _cleanup_strv_free_ char **d = NULL; + + assert(strv); + + d = strv_split_nulstr(dirs); + if (!d) + return -ENOMEM; + + return conf_files_insert(strv, root, d, path); +} + int conf_files_list_strv(char ***strv, const char *suffix, const char *root, unsigned flags, const char* const* dirs) { _cleanup_strv_free_ char **copy = NULL; @@ -246,14 +258,14 @@ int conf_files_list(char ***strv, const char *suffix, const char *root, unsigned return conf_files_list_strv_internal(strv, suffix, root, flags, dirs); } -int conf_files_list_nulstr(char ***strv, const char *suffix, const char *root, unsigned flags, const char *d) { - _cleanup_strv_free_ char **dirs = NULL; +int conf_files_list_nulstr(char ***strv, const char *suffix, const char *root, unsigned flags, const char *dirs) { + _cleanup_strv_free_ char **d = NULL; assert(strv); - dirs = strv_split_nulstr(d); - if (!dirs) + d = strv_split_nulstr(dirs); + if (!d) return -ENOMEM; - return conf_files_list_strv_internal(strv, suffix, root, flags, dirs); + return conf_files_list_strv_internal(strv, suffix, root, flags, d); } diff --git a/src/basic/conf-files.h b/src/basic/conf-files.h index ddee72782..5dc83578e 100644 --- a/src/basic/conf-files.h +++ b/src/basic/conf-files.h @@ -28,4 +28,5 @@ enum { int conf_files_list(char ***ret, const char *suffix, const char *root, unsigned flags, const char *dir, ...); int conf_files_list_strv(char ***ret, const char *suffix, const char *root, unsigned flags, const char* const* dirs); int conf_files_list_nulstr(char ***ret, const char *suffix, const char *root, unsigned flags, const char *dirs); -int conf_files_insert(char ***strv, const char *root, const char *dirs, const char *path); +int conf_files_insert(char ***strv, const char *root, char **dirs, const char *path); +int conf_files_insert_nulstr(char ***strv, const char *root, const char *dirs, const char *path);