naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
84b277
From 123a76e6190cb2a4669d39e12983f46e27b11163 Mon Sep 17 00:00:00 2001
84b277
From: Michael Marineau <michael.marineau@coreos.com>
84b277
Date: Thu, 13 Mar 2014 21:32:12 -0700
84b277
Subject: [PATCH] shared: add root argument to search_and_fopen
84b277
84b277
This adds the same root argument to search_and_fopen that
84b277
conf_files_list already has. Tools that use those two functions as a
84b277
pair can now be easily modified to load configuration files from an
84b277
alternate root filesystem tree.
84b277
84b277
Conflicts:
84b277
	src/shared/util.h
84b277
84b277
(cherry picked from commit 4cf7ea556aa1e74f9b34d4467f36d46a1bb25da3)
84b277
84b277
Related: #1111199
84b277
---
84b277
 src/binfmt/binfmt.c             |  2 +-
84b277
 src/modules-load/modules-load.c |  2 +-
84b277
 src/shared/util.c               | 12 ++++++------
84b277
 src/shared/util.h               |  4 ++--
84b277
 src/sysctl/sysctl.c             |  2 +-
84b277
 src/tmpfiles/tmpfiles.c         |  2 +-
84b277
 6 files changed, 12 insertions(+), 12 deletions(-)
84b277
84b277
diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c
84b277
index 5a42b3d..3fff89a 100644
84b277
--- a/src/binfmt/binfmt.c
84b277
+++ b/src/binfmt/binfmt.c
84b277
@@ -85,7 +85,7 @@ static int apply_file(const char *path, bool ignore_enoent) {
84b277
 
84b277
         assert(path);
84b277
 
84b277
-        r = search_and_fopen_nulstr(path, "re", conf_file_dirs, &f);
84b277
+        r = search_and_fopen_nulstr(path, "re", NULL, conf_file_dirs, &f);
84b277
         if (r < 0) {
84b277
                 if (ignore_enoent && r == -ENOENT)
84b277
                         return 0;
84b277
diff --git a/src/modules-load/modules-load.c b/src/modules-load/modules-load.c
84b277
index 49ee420..cba7c55 100644
84b277
--- a/src/modules-load/modules-load.c
84b277
+++ b/src/modules-load/modules-load.c
84b277
@@ -181,7 +181,7 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent
84b277
         assert(ctx);
84b277
         assert(path);
84b277
 
84b277
-        r = search_and_fopen_nulstr(path, "re", conf_file_dirs, &f);
84b277
+        r = search_and_fopen_nulstr(path, "re", NULL, conf_file_dirs, &f);
84b277
         if (r < 0) {
84b277
                 if (ignore_enoent && r == -ENOENT)
84b277
                         return 0;
84b277
diff --git a/src/shared/util.c b/src/shared/util.c
84b277
index a5163fb..e313ea9 100644
84b277
--- a/src/shared/util.c
84b277
+++ b/src/shared/util.c
84b277
@@ -5674,14 +5674,14 @@ int on_ac_power(void) {
84b277
         return found_online || !found_offline;
84b277
 }
84b277
 
84b277
-static int search_and_fopen_internal(const char *path, const char *mode, char **search, FILE **_f) {
84b277
+static int search_and_fopen_internal(const char *path, const char *mode, const char *root, char **search, FILE **_f) {
84b277
         char **i;
84b277
 
84b277
         assert(path);
84b277
         assert(mode);
84b277
         assert(_f);
84b277
 
84b277
-        if (!path_strv_canonicalize_absolute_uniq(search, NULL))
84b277
+        if (!path_strv_canonicalize_absolute_uniq(search, root))
84b277
                 return -ENOMEM;
84b277
 
84b277
         STRV_FOREACH(i, search) {
84b277
@@ -5705,7 +5705,7 @@ static int search_and_fopen_internal(const char *path, const char *mode, char **
84b277
         return -ENOENT;
84b277
 }
84b277
 
84b277
-int search_and_fopen(const char *path, const char *mode, const char **search, FILE **_f) {
84b277
+int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f) {
84b277
         _cleanup_strv_free_ char **copy = NULL;
84b277
 
84b277
         assert(path);
84b277
@@ -5728,10 +5728,10 @@ int search_and_fopen(const char *path, const char *mode, const char **search, FI
84b277
         if (!copy)
84b277
                 return -ENOMEM;
84b277
 
84b277
-        return search_and_fopen_internal(path, mode, copy, _f);
84b277
+        return search_and_fopen_internal(path, mode, root, copy, _f);
84b277
 }
84b277
 
84b277
-int search_and_fopen_nulstr(const char *path, const char *mode, const char *search, FILE **_f) {
84b277
+int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f) {
84b277
         _cleanup_strv_free_ char **s = NULL;
84b277
 
84b277
         if (path_is_absolute(path)) {
84b277
@@ -5750,7 +5750,7 @@ int search_and_fopen_nulstr(const char *path, const char *mode, const char *sear
84b277
         if (!s)
84b277
                 return -ENOMEM;
84b277
 
84b277
-        return search_and_fopen_internal(path, mode, s, _f);
84b277
+        return search_and_fopen_internal(path, mode, root, s, _f);
84b277
 }
84b277
 
84b277
 int create_tmp_dir(char template[], char** dir_name) {
84b277
diff --git a/src/shared/util.h b/src/shared/util.h
84b277
index d11fa07..3f30917 100644
84b277
--- a/src/shared/util.h
84b277
+++ b/src/shared/util.h
84b277
@@ -628,8 +628,8 @@ char *strip_tab_ansi(char **p, size_t *l);
84b277
 
84b277
 int on_ac_power(void);
84b277
 
84b277
-int search_and_fopen(const char *path, const char *mode, const char **search, FILE **_f);
84b277
-int search_and_fopen_nulstr(const char *path, const char *mode, const char *search, FILE **_f);
84b277
+int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f);
84b277
+int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f);
84b277
 int create_tmp_dir(char template[], char** dir_name);
84b277
 
84b277
 #define FOREACH_LINE(line, f, on_error)                         \
84b277
diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c
84b277
index 878c923..a9d4d53 100644
84b277
--- a/src/sysctl/sysctl.c
84b277
+++ b/src/sysctl/sysctl.c
84b277
@@ -123,7 +123,7 @@ static int parse_file(Hashmap *sysctl_options, const char *path, bool ignore_eno
84b277
 
84b277
         assert(path);
84b277
 
84b277
-        r = search_and_fopen_nulstr(path, "re", conf_file_dirs, &f);
84b277
+        r = search_and_fopen_nulstr(path, "re", NULL, conf_file_dirs, &f);
84b277
         if (r < 0) {
84b277
                 if (ignore_enoent && r == -ENOENT)
84b277
                         return 0;
84b277
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
84b277
index 309fa07..32f9088 100644
84b277
--- a/src/tmpfiles/tmpfiles.c
84b277
+++ b/src/tmpfiles/tmpfiles.c
84b277
@@ -1368,7 +1368,7 @@ static int read_config_file(const char *fn, bool ignore_enoent) {
84b277
 
84b277
         assert(fn);
84b277
 
84b277
-        r = search_and_fopen_nulstr(fn, "re", conf_file_dirs, &f);
84b277
+        r = search_and_fopen_nulstr(fn, "re", NULL, conf_file_dirs, &f);
84b277
         if (r < 0) {
84b277
                 if (ignore_enoent && r == -ENOENT)
84b277
                         return 0;