summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-path
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-03-24 16:04:50 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-03-27 20:12:45 +0100
commit9c5bb2033db0c0927593b929ff760b69295a9f70 (patch)
tree0580eaaf44600f2562bdabd53c8ee981879fef95 /src/libsystemd/sd-path
parentce7eb6aa84b24d411ede7ed570faba78ee084493 (diff)
downloadsystemd-9c5bb2033db0c0927593b929ff760b69295a9f70.tar.gz
path: show various systemd directories and search paths too
So far we had various ad hoc APIs to query search paths: systemd-analyze unit-paths, lookup_paths_log(), the pkgconfig file, debug logs emitted by systemd-analyze cat-config. But answering a simple question "what is the search path for tmpfiles, sysusers, .network files, ..." is surprisingly hard. I think we should have an api that makes it easy to query this. Pkgconfig is not bad, but it is primarily a development tool, so it's not available in many context. Also it can't provide support for paths which are influenced by environment variables, and I'd like to be able to answer the question "what is the search path for ..., assuming that VAR_FOO=... is set?". Extending sd-path to support more of our internal paths seems to be most flexible solution. We already have systemd-path which provides a nice way to query, and we can add stuff like optional descriptions later on. We we essentially get a nice programmatic and commmandline apis for the price of one.
Diffstat (limited to 'src/libsystemd/sd-path')
-rw-r--r--src/libsystemd/sd-path/sd-path.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c
index 8bdc2435a3..edc32fbd87 100644
--- a/src/libsystemd/sd-path/sd-path.c
+++ b/src/libsystemd/sd-path/sd-path.c
@@ -7,6 +7,7 @@
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
+#include "path-lookup.h"
#include "path-util.h"
#include "string-util.h"
#include "strv.h"
@@ -318,6 +319,76 @@ static int get_path(uint64_t type, char **buffer, const char **ret) {
case SD_PATH_USER_DESKTOP:
return from_user_dir("XDG_DESKTOP_DIR", buffer, ret);
+
+ case SD_PATH_SYSTEMD_UTIL_DIR:
+ *ret = ROOTPREFIX "lib/systemd";
+ return 0;
+
+ case SD_PATH_SYSTEMD_SYSTEM_UNIT_DIR:
+ *ret = SYSTEM_DATA_UNIT_PATH;
+ return 0;
+
+ case SD_PATH_SYSTEMD_SYSTEM_PRESET_DIR:
+ *ret = ROOTPREFIX "lib/systemd/system-preset";
+ return 0;
+
+ case SD_PATH_SYSTEMD_USER_UNIT_DIR:
+ *ret = USER_DATA_UNIT_PATH;
+ return 0;
+
+ case SD_PATH_SYSTEMD_USER_PRESET_DIR:
+ *ret = ROOTPREFIX "lib/systemd/user-preset";
+ return 0;
+
+ case SD_PATH_SYSTEMD_SYSTEM_CONF_DIR:
+ *ret = SYSTEM_CONFIG_UNIT_PATH; // FIXME: _DIR vs. _PATH
+ return 0;
+
+ case SD_PATH_SYSTEMD_USER_CONF_DIR:
+ *ret = USER_CONFIG_UNIT_PATH; // FIXME: _DIR vs. _PATH
+ return 0;
+
+ case SD_PATH_SYSTEMD_SYSTEM_GENERATOR_DIR:
+ *ret = SYSTEM_GENERATOR_PATH; // FIXME: _DIR vs. _PATH
+ return 0;
+
+ case SD_PATH_SYSTEMD_USER_GENERATOR_DIR:
+ *ret = USER_GENERATOR_PATH; // FIXME: _DIR vs. _PATH
+ return 0;
+
+ case SD_PATH_SYSTEMD_SLEEP_DIR:
+ *ret = ROOTPREFIX "lib/systemd/system-sleep";
+ return 0;
+
+ case SD_PATH_SYSTEMD_SHUTDOWN_DIR:
+ *ret = ROOTPREFIX "lib/systemd/system-shutdown";
+ return 0;
+
+ /* FIXME: systemd.pc uses ${prefix}, but CONF_PATHS_NULSTR doesn't.
+ * Should ${prefix} use in systemd.pc be removed? */
+ case SD_PATH_TMPFILES_DIR:
+ *ret = "/usr/lib/tmpfiles.d";
+ return 0;
+
+ case SD_PATH_SYSUSERS_DIR:
+ *ret = "/usr/lib/sysusers.d";
+ return 0;
+
+ case SD_PATH_SYSCTL_DIR:
+ *ret = "/usr/lib/sysctl.d";
+ return 0;
+
+ case SD_PATH_BINFMT_DIR:
+ *ret = "/usr/lib/binfmt.d";
+ return 0;
+
+ case SD_PATH_MODULES_LOAD_DIR:
+ *ret = "/usr/lib/modules-load.d";
+ return 0;
+
+ case SD_PATH_CATALOG_DIR:
+ *ret = "/usr/lib/systemd/catalog";
+ return 0;
}
return -EOPNOTSUPP;
@@ -450,6 +521,7 @@ static int search_from_environment(
#endif
static int get_search(uint64_t type, char ***list) {
+ int r;
assert(list);
@@ -535,9 +607,34 @@ static int get_search(uint64_t type, char ***list) {
case SD_PATH_SEARCH_BINARIES_DEFAULT:
return strv_from_nulstr(list, DEFAULT_PATH_NULSTR);
+ case SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH:
+ case SD_PATH_SYSTEMD_USER_UNIT_PATH: {
+ _cleanup_(lookup_paths_free) LookupPaths lp = {};
+ const UnitFileScope scope = type == SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH ?
+ UNIT_FILE_SYSTEM : UNIT_FILE_USER;
+
+ r = lookup_paths_init(&lp, scope, 0, NULL);
+ if (r < 0)
+ return r;
+ *list = TAKE_PTR(lp.search_path);
+ return 0;
}
+ case SD_PATH_SYSTEMD_SYSTEM_GENERATOR_PATH:
+ case SD_PATH_SYSTEMD_USER_GENERATOR_PATH: {
+ char **t;
+ const UnitFileScope scope = type == SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH ?
+ UNIT_FILE_SYSTEM : UNIT_FILE_USER;
+
+ t = generator_binary_paths(scope);
+ if (!t)
+ return -ENOMEM;
+
+ *list = t;
+ return 0;
+ }}
+
return -EOPNOTSUPP;
}