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
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)
"No paths specified, refusing.");
*ret_paths = TAKE_PTR(l);
- return 0;
+ return 1;
}
}
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;
}