daandemeyer / rpms / systemd

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