summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-path/sd-path.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd/sd-path/sd-path.c')
-rw-r--r--src/libsystemd/sd-path/sd-path.c48
1 files changed, 20 insertions, 28 deletions
diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c
index 419c763668..2845f91e1b 100644
--- a/src/libsystemd/sd-path/sd-path.c
+++ b/src/libsystemd/sd-path/sd-path.c
@@ -1,21 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
/***
- This file is part of systemd.
-
- Copyright 2014 Lennart Poettering
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "sd-path.h"
@@ -348,6 +332,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,
@@ -566,19 +551,31 @@ 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;
}
_public_ int sd_path_search(uint64_t type, const char *suffix, char ***paths) {
- char **l, **i, **j, **n;
+ char **i, **j;
+ _cleanup_strv_free_ char **l = NULL, **n = NULL;
int r;
assert_return(paths, -EINVAL);
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,
@@ -601,7 +598,7 @@ _public_ int sd_path_search(uint64_t type, const char *suffix, char ***paths) {
l[0] = p;
l[1] = NULL;
- *paths = l;
+ *paths = TAKE_PTR(l);
return 0;
}
@@ -610,15 +607,13 @@ _public_ int sd_path_search(uint64_t type, const char *suffix, char ***paths) {
return r;
if (!suffix) {
- *paths = l;
+ *paths = TAKE_PTR(l);
return 0;
}
n = new(char*, strv_length(l)+1);
- if (!n) {
- strv_free(l);
+ if (!n)
return -ENOMEM;
- }
j = n;
STRV_FOREACH(i, l) {
@@ -628,16 +623,13 @@ _public_ int sd_path_search(uint64_t type, const char *suffix, char ***paths) {
else
*j = strjoin(*i, "/", suffix);
- if (!*j) {
- strv_free(l);
- strv_free(n);
+ if (!*j)
return -ENOMEM;
- }
j++;
}
*j = NULL;
- *paths = n;
+ *paths = TAKE_PTR(n);
return 0;
}