diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-02-25 13:16:36 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-02-25 13:24:53 +0100 |
commit | 33d31c0e60502a926e68b653055a4744166c5e3d (patch) | |
tree | 7b50f70386fa013e31d19c4097c1446e58c2a073 /src | |
parent | 9c274488a9168f8284dc99882856ca79ce2aa132 (diff) | |
download | systemd-33d31c0e60502a926e68b653055a4744166c5e3d.tar.gz |
env-util: fix parameter handling of parse_env_extension_hierarchies() + getenv_path_list()
Our coding style dictates we should not clobber return parameters on
failure, and always initialize them on success. Do so here.
This changes getenv_path_list() to return ENXIO if the env var is not
set, which is similar to how we handle this in getenv_bool().
This drops debug logging from parse_env_extension_hierarchies(), since
it's done anyway in getenv_path_list()
Follow-up for: #18018
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/env-util.c | 6 | ||||
-rw-r--r-- | src/shared/extension-release.c | 16 |
2 files changed, 11 insertions, 11 deletions
diff --git a/src/basic/env-util.c b/src/basic/env-util.c index 7fa598a3b5..c110a750a5 100644 --- a/src/basic/env-util.c +++ b/src/basic/env-util.c @@ -813,11 +813,9 @@ int getenv_path_list(const char *name, char ***ret_paths) { assert(name); assert(ret_paths); - *ret_paths = NULL; - e = secure_getenv(name); if (!e) - return 0; + return -ENXIO; r = strv_split_full(&l, e, ":", EXTRACT_DONT_COALESCE_SEPARATORS); if (r < 0) @@ -842,5 +840,5 @@ int getenv_path_list(const char *name, char ***ret_paths) { "No paths specified, refusing."); *ret_paths = TAKE_PTR(l); - return 0; + return 1; } diff --git a/src/shared/extension-release.c b/src/shared/extension-release.c index 5676e2c063..29cbecbf57 100644 --- a/src/shared/extension-release.c +++ b/src/shared/extension-release.c @@ -79,16 +79,18 @@ int extension_release_validate( } int parse_env_extension_hierarchies(char ***ret_hierarchies) { + _cleanup_free_ char **l = NULL; int r; - r = getenv_path_list("SYSTEMD_SYSEXT_HIERARCHIES", ret_hierarchies); - if (r < 0) - return log_debug_errno(r, "Failed to parse SYSTEMD_SYSEXT_HIERARCHIES environment variable : %m"); - if (!*ret_hierarchies) { - *ret_hierarchies = strv_new("/usr", "/opt"); - if (!*ret_hierarchies) + r = getenv_path_list("SYSTEMD_SYSEXT_HIERARCHIES", &l); + if (r == -ENXIO) { + /* Default when unset */ + l = strv_new("/usr", "/opt"); + if (!l) return -ENOMEM; - } + } else if (r < 0) + return r; + *ret_hierarchies = TAKE_PTR(l); return 0; } |