]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
env-util: fix parameter handling of parse_env_extension_hierarchies() + getenv_path_l...
authorLennart Poettering <lennart@poettering.net>
Thu, 25 Feb 2021 12:16:36 +0000 (13:16 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 25 Feb 2021 12:24:53 +0000 (13:24 +0100)
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

src/basic/env-util.c
src/shared/extension-release.c

index 7fa598a3b533d660b8da1535634478807688fe42..c110a750a55dd49bd70b1f66c9968b4502a4a032 100644 (file)
@@ -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;
 }
index 5676e2c063001054b9d071038ac2f5ce5e031f78..29cbecbf57d02a5f6a359b55749668474d1e70a3 100644 (file)
@@ -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;
 }