ryantimwilson / rpms / systemd

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