summaryrefslogtreecommitdiff
path: root/src/basic/conf-files.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-05-10 11:14:23 -0700
committerGitHub <noreply@github.com>2018-05-10 11:14:23 -0700
commit81321f51cf7968060a3ad458c199d63a6999f2da (patch)
treee0b4809142cb2aef722ed4b3ee84e09b82a6ad5e /src/basic/conf-files.c
parent41b9d436b2739cbe8bf9482b665d85d59d06bc0e (diff)
parenta826d4f7d01b144df191cf7a6de729b678cdb1d9 (diff)
downloadsystemd-81321f51cf7968060a3ad458c199d63a6999f2da.tar.gz
Merge pull request #8824 from keszybz/analyze-show-config
systemd-analyze show-config
Diffstat (limited to 'src/basic/conf-files.c')
-rw-r--r--src/basic/conf-files.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/basic/conf-files.c b/src/basic/conf-files.c
index b5cad5a6e3..1112dbf2f8 100644
--- a/src/basic/conf-files.c
+++ b/src/basic/conf-files.c
@@ -13,6 +13,7 @@
#include <string.h>
#include "conf-files.h"
+#include "def.h"
#include "dirent-util.h"
#include "fd-util.h"
#include "hashmap.h"
@@ -23,6 +24,7 @@
#include "stat-util.h"
#include "string-util.h"
#include "strv.h"
+#include "terminal-util.h"
#include "util.h"
static int files_add(Hashmap *h, const char *suffix, const char *root, unsigned flags, const char *path) {
@@ -256,3 +258,71 @@ 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 *root, const char *name) {
+ _cleanup_strv_free_ char **dirs = NULL, **files = NULL;
+ _cleanup_free_ char *path = NULL;
+ const char *dir;
+ char **t;
+ int r;
+
+ NULSTR_FOREACH(dir, CONF_PATHS_NULSTR("")) {
+ assert(endswith(dir, "/"));
+ r = strv_extendf(&dirs, "%s%s.d", dir, name);
+ if (r < 0)
+ return log_error("Failed to build directory list: %m");
+ }
+
+ r = conf_files_list_strv(&files, ".conf", root, 0, (const char* const*) dirs);
+ if (r < 0)
+ return log_error_errno(r, "Failed to query file list: %m");
+
+ path = path_join(root, "/etc", name);
+ if (!path)
+ return log_oom();
+
+ if (DEBUG_LOGGING) {
+ log_debug("Looking for configuration in:");
+ log_debug(" %s", path);
+ STRV_FOREACH(t, dirs)
+ log_debug(" %s/*.conf", *t);
+ }
+
+ /* show */
+ return cat_files(path, files, CAT_FLAGS_MAIN_FILE_OPTIONAL);
+}