+/* SPDX-License-Identifier: LGPL-2.1+ */
/***
This file is part of systemd.
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include "util.h"
+#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 "sd-path.h"
-#include "missing.h"
+#include "user-util.h"
+#include "util.h"
static int from_environment(const char *envname, const char *fallback, const char **ret) {
assert(ret);
if (endswith(h, "/"))
cc = strappend(h, suffix);
else
- cc = strjoin(h, "/", suffix, NULL);
+ cc = strjoin(h, "/", suffix);
if (!cc)
return -ENOMEM;
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;
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)
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";
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,
if (endswith(ret, "/"))
cc = strappend(ret, suffix);
else
- cc = strjoin(ret, "/", suffix, NULL);
+ cc = strjoin(ret, "/", suffix);
free(buffer);
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);
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);
".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);
false,
"/usr/local/lib",
"/usr/lib",
-#ifdef HAVE_SPLIT_USR
+#if HAVE_SPLIT_USR
"/lib",
#endif
NULL);
"LD_LIBRARY_PATH",
true,
LIBDIR,
-#ifdef HAVE_SPLIT_USR
+#if HAVE_SPLIT_USR
ROOTLIBDIR,
#endif
NULL);
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;
}
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,
if (endswith(*i, "/"))
*j = strappend(*i, suffix);
else
- *j = strjoin(*i, "/", suffix, NULL);
+ *j = strjoin(*i, "/", suffix);
if (!*j) {
strv_free(l);