X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=src%2Flibsystemd%2Fsd-path%2Fsd-path.c;h=b2e8e63c1b3e594965f5ff0dee5757da504d6f7e;hb=e12d446b6623cedaf2b92c5e935312f7ade6cfef;hp=2467c126aee5e35bbaa10f10aee9118a9c483b3b;hpb=3ffd4af22052963e7a29431721ee204e634bea75;p=thirdparty%2Fsystemd.git diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c index 2467c126aee..b2e8e63c1b3 100644 --- a/src/libsystemd/sd-path/sd-path.c +++ b/src/libsystemd/sd-path/sd-path.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. @@ -19,12 +20,16 @@ #include "sd-path.h" +#include "alloc-util.h" #include "architecture.h" #include "fd-util.h" +#include "fileio.h" +#include "fs-util.h" #include "missing.h" #include "path-util.h" #include "string-util.h" #include "strv.h" +#include "user-util.h" #include "util.h" static int from_environment(const char *envname, const char *fallback, const char **ret) { @@ -74,7 +79,7 @@ static int from_home_dir(const char *envname, const char *suffix, char **buffer, if (endswith(h, "/")) cc = strappend(h, suffix); else - cc = strjoin(h, "/", suffix, NULL); + cc = strjoin(h, "/", suffix); if (!cc) return -ENOMEM; @@ -86,7 +91,8 @@ static int from_home_dir(const char *envname, const char *suffix, char **buffer, static int from_user_dir(const char *field, char **buffer, const char **ret) { _cleanup_fclose_ FILE *f = NULL; _cleanup_free_ char *b = NULL; - const char *fn = NULL; + _cleanup_free_ const char *fn = NULL; + const char *c = NULL; char line[LINE_MAX]; size_t n; int r; @@ -95,10 +101,14 @@ static int from_user_dir(const char *field, char **buffer, const char **ret) { assert(buffer); assert(ret); - r = from_home_dir(NULL, ".config/user-dirs.dirs", &b, &fn); + r = from_home_dir("XDG_CONFIG_HOME", ".config", &b, &c); if (r < 0) return r; + fn = strappend(c, "/user-dirs.dirs"); + if (!fn) + return -ENOMEM; + f = fopen(fn, "re"); if (!f) { if (errno == ENOENT) @@ -211,10 +221,10 @@ static int get_path(uint64_t type, char **buffer, const char **ret) { switch (type) { case SD_PATH_TEMPORARY: - return from_environment("TMPDIR", "/tmp", ret); + return tmp_dir(ret); case SD_PATH_TEMPORARY_LARGE: - return from_environment("TMPDIR", "/var/tmp", ret); + return var_tmp_dir(ret); case SD_PATH_SYSTEM_BINARIES: *ret = "/usr/bin"; @@ -338,6 +348,7 @@ _public_ int sd_path_home(uint64_t type, const char *suffix, char **path) { if (IN_SET(type, SD_PATH_SEARCH_BINARIES, + SD_PATH_SEARCH_BINARIES_DEFAULT, SD_PATH_SEARCH_LIBRARY_PRIVATE, SD_PATH_SEARCH_LIBRARY_ARCH, SD_PATH_SEARCH_SHARED, @@ -379,7 +390,7 @@ _public_ int sd_path_home(uint64_t type, const char *suffix, char **path) { if (endswith(ret, "/")) cc = strappend(ret, suffix); else - cc = strjoin(ret, "/", suffix, NULL); + cc = strjoin(ret, "/", suffix); free(buffer); @@ -447,7 +458,7 @@ static int search_from_environment( if (endswith(e, "/")) h = strappend(e, home_suffix); else - h = strjoin(e, "/", home_suffix, NULL); + h = strjoin(e, "/", home_suffix); if (!h) { strv_free(l); @@ -468,6 +479,12 @@ static int search_from_environment( return 0; } +#if HAVE_SPLIT_BIN +# define ARRAY_SBIN_BIN(x) x "sbin", x "bin" +#else +# define ARRAY_SBIN_BIN(x) x "bin" +#endif + static int get_search(uint64_t type, char ***list) { assert(list); @@ -480,13 +497,10 @@ static int get_search(uint64_t type, char ***list) { ".local/bin", "PATH", true, - "/usr/local/sbin", - "/usr/local/bin", - "/usr/sbin", - "/usr/bin", -#ifdef HAVE_SPLIT_USR - "/sbin", - "/bin", + ARRAY_SBIN_BIN("/usr/local/"), + ARRAY_SBIN_BIN("/usr/"), +#if HAVE_SPLIT_USR + ARRAY_SBIN_BIN("/"), #endif NULL); @@ -498,7 +512,7 @@ static int get_search(uint64_t type, char ***list) { false, "/usr/local/lib", "/usr/lib", -#ifdef HAVE_SPLIT_USR +#if HAVE_SPLIT_USR "/lib", #endif NULL); @@ -510,7 +524,7 @@ static int get_search(uint64_t type, char ***list) { "LD_LIBRARY_PATH", true, LIBDIR, -#ifdef HAVE_SPLIT_USR +#if HAVE_SPLIT_USR ROOTLIBDIR, #endif NULL); @@ -553,7 +567,17 @@ static int get_search(uint64_t type, char ***list) { false, "/etc", NULL); - } + + case SD_PATH_SEARCH_BINARIES_DEFAULT: { + char **t; + + t = strv_split_nulstr(DEFAULT_PATH_NULSTR); + if (!t) + return -ENOMEM; + + *list = t; + return 0; + }} return -EOPNOTSUPP; } @@ -566,6 +590,7 @@ _public_ int sd_path_search(uint64_t type, const char *suffix, char ***paths) { if (!IN_SET(type, SD_PATH_SEARCH_BINARIES, + SD_PATH_SEARCH_BINARIES_DEFAULT, SD_PATH_SEARCH_LIBRARY_PRIVATE, SD_PATH_SEARCH_LIBRARY_ARCH, SD_PATH_SEARCH_SHARED, @@ -613,7 +638,7 @@ _public_ int sd_path_search(uint64_t type, const char *suffix, char ***paths) { if (endswith(*i, "/")) *j = strappend(*i, suffix); else - *j = strjoin(*i, "/", suffix, NULL); + *j = strjoin(*i, "/", suffix); if (!*j) { strv_free(l);