mirror of
https://github.com/clearlinux/systemd-stable.git
synced 2026-10-09 19:55:32 +00:00
shared: add root argument to search_and_fopen
This adds the same root argument to search_and_fopen that conf_files_list already has. Tools that use those two functions as a pair can now be easily modified to load configuration files from an alternate root filesystem tree. (cherry picked from commit4cf7ea556a) (cherry picked from commit8d4847827d) Conflicts: src/shared/util.h
This commit is contained in:
committed by
Zbigniew Jędrzejewski-Szmek
parent
806e59a1e1
commit
a2d2b499ee
+1
-1
@@ -85,7 +85,7 @@ static int apply_file(const char *path, bool ignore_enoent) {
|
||||
|
||||
assert(path);
|
||||
|
||||
r = search_and_fopen_nulstr(path, "re", conf_file_dirs, &f);
|
||||
r = search_and_fopen_nulstr(path, "re", NULL, conf_file_dirs, &f);
|
||||
if (r < 0) {
|
||||
if (ignore_enoent && r == -ENOENT)
|
||||
return 0;
|
||||
|
||||
@@ -181,7 +181,7 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent
|
||||
assert(ctx);
|
||||
assert(path);
|
||||
|
||||
r = search_and_fopen_nulstr(path, "re", conf_file_dirs, &f);
|
||||
r = search_and_fopen_nulstr(path, "re", NULL, conf_file_dirs, &f);
|
||||
if (r < 0) {
|
||||
if (ignore_enoent && r == -ENOENT)
|
||||
return 0;
|
||||
|
||||
+6
-6
@@ -5687,14 +5687,14 @@ int on_ac_power(void) {
|
||||
return found_online || !found_offline;
|
||||
}
|
||||
|
||||
static int search_and_fopen_internal(const char *path, const char *mode, char **search, FILE **_f) {
|
||||
static int search_and_fopen_internal(const char *path, const char *mode, const char *root, char **search, FILE **_f) {
|
||||
char **i;
|
||||
|
||||
assert(path);
|
||||
assert(mode);
|
||||
assert(_f);
|
||||
|
||||
if (!path_strv_canonicalize_absolute_uniq(search, NULL))
|
||||
if (!path_strv_canonicalize_absolute_uniq(search, root))
|
||||
return -ENOMEM;
|
||||
|
||||
STRV_FOREACH(i, search) {
|
||||
@@ -5718,7 +5718,7 @@ static int search_and_fopen_internal(const char *path, const char *mode, char **
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
int search_and_fopen(const char *path, const char *mode, const char **search, FILE **_f) {
|
||||
int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f) {
|
||||
_cleanup_strv_free_ char **copy = NULL;
|
||||
|
||||
assert(path);
|
||||
@@ -5741,10 +5741,10 @@ int search_and_fopen(const char *path, const char *mode, const char **search, FI
|
||||
if (!copy)
|
||||
return -ENOMEM;
|
||||
|
||||
return search_and_fopen_internal(path, mode, copy, _f);
|
||||
return search_and_fopen_internal(path, mode, root, copy, _f);
|
||||
}
|
||||
|
||||
int search_and_fopen_nulstr(const char *path, const char *mode, const char *search, FILE **_f) {
|
||||
int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f) {
|
||||
_cleanup_strv_free_ char **s = NULL;
|
||||
|
||||
if (path_is_absolute(path)) {
|
||||
@@ -5763,7 +5763,7 @@ int search_and_fopen_nulstr(const char *path, const char *mode, const char *sear
|
||||
if (!s)
|
||||
return -ENOMEM;
|
||||
|
||||
return search_and_fopen_internal(path, mode, s, _f);
|
||||
return search_and_fopen_internal(path, mode, root, s, _f);
|
||||
}
|
||||
|
||||
int create_tmp_dir(char template[], char** dir_name) {
|
||||
|
||||
+2
-2
@@ -629,8 +629,8 @@ char *strip_tab_ansi(char **p, size_t *l);
|
||||
|
||||
int on_ac_power(void);
|
||||
|
||||
int search_and_fopen(const char *path, const char *mode, const char **search, FILE **_f);
|
||||
int search_and_fopen_nulstr(const char *path, const char *mode, const char *search, FILE **_f);
|
||||
int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f);
|
||||
int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f);
|
||||
int create_tmp_dir(char template[], char** dir_name);
|
||||
|
||||
#define FOREACH_LINE(line, f, on_error) \
|
||||
|
||||
+1
-1
@@ -137,7 +137,7 @@ static int parse_file(Hashmap *sysctl_options, const char *path, bool ignore_eno
|
||||
|
||||
assert(path);
|
||||
|
||||
r = search_and_fopen_nulstr(path, "re", conf_file_dirs, &f);
|
||||
r = search_and_fopen_nulstr(path, "re", NULL, conf_file_dirs, &f);
|
||||
if (r < 0) {
|
||||
if (ignore_enoent && r == -ENOENT)
|
||||
return 0;
|
||||
|
||||
@@ -1364,7 +1364,7 @@ static int read_config_file(const char *fn, bool ignore_enoent) {
|
||||
|
||||
assert(fn);
|
||||
|
||||
r = search_and_fopen_nulstr(fn, "re", conf_file_dirs, &f);
|
||||
r = search_and_fopen_nulstr(fn, "re", NULL, conf_file_dirs, &f);
|
||||
if (r < 0) {
|
||||
if (ignore_enoent && r == -ENOENT)
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user