diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-04-26 19:07:54 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-04-27 10:06:24 +0200 |
commit | ceaaeb9bab2efee578971615c584c4c91b9d3858 (patch) | |
tree | e7102716d7110035811a019cf36c9484ab32bee1 /src/basic/conf-files.c | |
parent | 854a42fb2e9db1b9eaa381559d7671f2e9b3a0f1 (diff) | |
download | systemd-ceaaeb9bab2efee578971615c584c4c91b9d3858.tar.gz |
tmpfiles: add --cat-config
This implements similar logic as conf_files_cat(), but with slightly different
file gathering logic. I also want to add support for replacement files later on,
so it seems better to keep those two file-gathering functions separate.
Diffstat (limited to 'src/basic/conf-files.c')
-rw-r--r-- | src/basic/conf-files.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/basic/conf-files.c b/src/basic/conf-files.c index 4c5ecb5cbb..29a85c018a 100644 --- a/src/basic/conf-files.c +++ b/src/basic/conf-files.c @@ -259,6 +259,41 @@ int conf_files_list_nulstr(char ***strv, const char *suffix, const char *root, u return conf_files_list_strv_internal(strv, suffix, root, flags, d); } +int conf_files_list_with_replacement( + const char *root, + char **config_dirs, + const char *replacement, + char ***files, + char **replace_file) { + + _cleanup_strv_free_ char **f = NULL; + _cleanup_free_ char *p = NULL; + int r; + + assert(config_dirs); + assert(files); + assert(replace_file || !replacement); + + r = conf_files_list_strv(&f, ".conf", root, 0, (const char* const*) config_dirs); + if (r < 0) + return log_error_errno(r, "Failed to enumerate config files: %m"); + + if (replacement) { + r = conf_files_insert(&f, root, config_dirs, replacement); + if (r < 0) + return log_error_errno(r, "Failed to extend config file list: %m"); + + p = path_join(root, replacement, NULL); + if (!p) + return log_oom(); + } + + *files = TAKE_PTR(f); + if (replace_file) + *replace_file = TAKE_PTR(p); + return 0; +} + int conf_files_cat(const char *name) { _cleanup_strv_free_ char **dirs = NULL, **files = NULL; const char *dir; |