From e12d446b6623cedaf2b92c5e935312f7ade6cfef Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 26 Mar 2018 09:51:12 +0200 Subject: [PATCH] systemd-path: allow the default search path to be queried --- man/systemd-path.xml | 7 ++++--- man/systemd.service.xml | 3 ++- src/libsystemd/sd-path/sd-path.c | 14 +++++++++++++- src/path/path.c | 1 + src/systemd/sd-path.h | 1 + 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/man/systemd-path.xml b/man/systemd-path.xml index 7144569d59d..025247c8839 100644 --- a/man/systemd-path.xml +++ b/man/systemd-path.xml @@ -52,7 +52,9 @@ - systemd-path OPTIONS NAME + systemd-path + OPTIONS + NAME @@ -81,8 +83,7 @@ - The printed paths are suffixed by the - specified string. + Printed paths are suffixed by the specified string. diff --git a/man/systemd.service.xml b/man/systemd.service.xml index e89cfe3f0ea..55a9c6fbdca 100644 --- a/man/systemd.service.xml +++ b/man/systemd.service.xml @@ -1029,7 +1029,8 @@ bin/ and sbin/. It is thus safe to use just the executable name in case of executables located in any of the "standard" directories, and an absolute path must be used in other cases. Using an absolute path is recommended to avoid - ambiguity. + ambiguity. Hint: this search path may be queried using + systemd-path search-binaries-default. Example: diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c index 419c763668e..b2e8e63c1b3 100644 --- a/src/libsystemd/sd-path/sd-path.c +++ b/src/libsystemd/sd-path/sd-path.c @@ -348,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, @@ -566,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; } @@ -579,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, diff --git a/src/path/path.c b/src/path/path.c index 0f029c4ae63..be17a444d3b 100644 --- a/src/path/path.c +++ b/src/path/path.c @@ -67,6 +67,7 @@ static const char* const path_table[_SD_PATH_MAX] = { [SD_PATH_USER_TEMPLATES] = "user-templates", [SD_PATH_USER_DESKTOP] = "user-desktop", [SD_PATH_SEARCH_BINARIES] = "search-binaries", + [SD_PATH_SEARCH_BINARIES_DEFAULT] = "search-binaries-default", [SD_PATH_SEARCH_LIBRARY_PRIVATE] = "search-library-private", [SD_PATH_SEARCH_LIBRARY_ARCH] = "search-library-arch", [SD_PATH_SEARCH_SHARED] = "search-shared", diff --git a/src/systemd/sd-path.h b/src/systemd/sd-path.h index 2dfc8967b4b..19f48b73ebb 100644 --- a/src/systemd/sd-path.h +++ b/src/systemd/sd-path.h @@ -74,6 +74,7 @@ enum { /* Search paths */ SD_PATH_SEARCH_BINARIES, + SD_PATH_SEARCH_BINARIES_DEFAULT, SD_PATH_SEARCH_LIBRARY_PRIVATE, SD_PATH_SEARCH_LIBRARY_ARCH, SD_PATH_SEARCH_SHARED, -- 2.39.2