X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=src%2Flibsystemd%2Fsd-path%2Fsd-path.c;h=b2e8e63c1b3e594965f5ff0dee5757da504d6f7e;hb=e12d446b6623cedaf2b92c5e935312f7ade6cfef;hp=b7aec1f20a6404fe62f5bab05642bbb34a6136b6;hpb=19180aadb562d43811b1c4f961f0e0b778c132ce;p=thirdparty%2Fsystemd.git diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c index b7aec1f20a6..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. @@ -23,6 +24,7 @@ #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" @@ -77,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; @@ -219,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"; @@ -346,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, @@ -387,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); @@ -455,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); @@ -476,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); @@ -488,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); @@ -506,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); @@ -518,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); @@ -561,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; } @@ -574,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, @@ -621,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);