From 009b80a48d3a2fa19a24c60ed58805a61854999c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 23 Mar 2020 15:09:05 +0100 Subject: [PATCH 01/18] path: align columns Without that it's really hard to see what items are in the table... --- src/path/path.c | 81 ++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/src/path/path.c b/src/path/path.c index 568b5fb04b..fa81632bb2 100644 --- a/src/path/path.c +++ b/src/path/path.c @@ -18,46 +18,46 @@ static const char *arg_suffix = NULL; static const char* const path_table[_SD_PATH_MAX] = { - [SD_PATH_TEMPORARY] = "temporary", - [SD_PATH_TEMPORARY_LARGE] = "temporary-large", - [SD_PATH_SYSTEM_BINARIES] = "system-binaries", - [SD_PATH_SYSTEM_INCLUDE] = "system-include", - [SD_PATH_SYSTEM_LIBRARY_PRIVATE] = "system-library-private", - [SD_PATH_SYSTEM_LIBRARY_ARCH] = "system-library-arch", - [SD_PATH_SYSTEM_SHARED] = "system-shared", - [SD_PATH_SYSTEM_CONFIGURATION_FACTORY] = "system-configuration-factory", - [SD_PATH_SYSTEM_STATE_FACTORY] = "system-state-factory", - [SD_PATH_SYSTEM_CONFIGURATION] = "system-configuration", - [SD_PATH_SYSTEM_RUNTIME] = "system-runtime", - [SD_PATH_SYSTEM_RUNTIME_LOGS] = "system-runtime-logs", - [SD_PATH_SYSTEM_STATE_PRIVATE] = "system-state-private", - [SD_PATH_SYSTEM_STATE_LOGS] = "system-state-logs", - [SD_PATH_SYSTEM_STATE_CACHE] = "system-state-cache", - [SD_PATH_SYSTEM_STATE_SPOOL] = "system-state-spool", - [SD_PATH_USER_BINARIES] = "user-binaries", - [SD_PATH_USER_LIBRARY_PRIVATE] = "user-library-private", - [SD_PATH_USER_LIBRARY_ARCH] = "user-library-arch", - [SD_PATH_USER_SHARED] = "user-shared", - [SD_PATH_USER_CONFIGURATION] = "user-configuration", - [SD_PATH_USER_RUNTIME] = "user-runtime", - [SD_PATH_USER_STATE_CACHE] = "user-state-cache", - [SD_PATH_USER] = "user", - [SD_PATH_USER_DOCUMENTS] = "user-documents", - [SD_PATH_USER_MUSIC] = "user-music", - [SD_PATH_USER_PICTURES] = "user-pictures", - [SD_PATH_USER_VIDEOS] = "user-videos", - [SD_PATH_USER_DOWNLOAD] = "user-download", - [SD_PATH_USER_PUBLIC] = "user-public", - [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", - [SD_PATH_SEARCH_CONFIGURATION_FACTORY] = "search-configuration-factory", - [SD_PATH_SEARCH_STATE_FACTORY] = "search-state-factory", - [SD_PATH_SEARCH_CONFIGURATION] = "search-configuration", + [SD_PATH_TEMPORARY] = "temporary", + [SD_PATH_TEMPORARY_LARGE] = "temporary-large", + [SD_PATH_SYSTEM_BINARIES] = "system-binaries", + [SD_PATH_SYSTEM_INCLUDE] = "system-include", + [SD_PATH_SYSTEM_LIBRARY_PRIVATE] = "system-library-private", + [SD_PATH_SYSTEM_LIBRARY_ARCH] = "system-library-arch", + [SD_PATH_SYSTEM_SHARED] = "system-shared", + [SD_PATH_SYSTEM_CONFIGURATION_FACTORY] = "system-configuration-factory", + [SD_PATH_SYSTEM_STATE_FACTORY] = "system-state-factory", + [SD_PATH_SYSTEM_CONFIGURATION] = "system-configuration", + [SD_PATH_SYSTEM_RUNTIME] = "system-runtime", + [SD_PATH_SYSTEM_RUNTIME_LOGS] = "system-runtime-logs", + [SD_PATH_SYSTEM_STATE_PRIVATE] = "system-state-private", + [SD_PATH_SYSTEM_STATE_LOGS] = "system-state-logs", + [SD_PATH_SYSTEM_STATE_CACHE] = "system-state-cache", + [SD_PATH_SYSTEM_STATE_SPOOL] = "system-state-spool", + [SD_PATH_USER_BINARIES] = "user-binaries", + [SD_PATH_USER_LIBRARY_PRIVATE] = "user-library-private", + [SD_PATH_USER_LIBRARY_ARCH] = "user-library-arch", + [SD_PATH_USER_SHARED] = "user-shared", + [SD_PATH_USER_CONFIGURATION] = "user-configuration", + [SD_PATH_USER_RUNTIME] = "user-runtime", + [SD_PATH_USER_STATE_CACHE] = "user-state-cache", + [SD_PATH_USER] = "user", + [SD_PATH_USER_DOCUMENTS] = "user-documents", + [SD_PATH_USER_MUSIC] = "user-music", + [SD_PATH_USER_PICTURES] = "user-pictures", + [SD_PATH_USER_VIDEOS] = "user-videos", + [SD_PATH_USER_DOWNLOAD] = "user-download", + [SD_PATH_USER_PUBLIC] = "user-public", + [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", + [SD_PATH_SEARCH_CONFIGURATION_FACTORY] = "search-configuration-factory", + [SD_PATH_SEARCH_STATE_FACTORY] = "search-state-factory", + [SD_PATH_SEARCH_CONFIGURATION] = "search-configuration", }; static int list_homes(void) { @@ -126,7 +126,6 @@ static int help(void) { } static int parse_argv(int argc, char *argv[]) { - enum { ARG_VERSION = 0x100, ARG_SUFFIX, From 4908de44b0a0409f84a7cdc5641b114d6ce8ba03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 23 Mar 2020 18:39:07 +0100 Subject: [PATCH 02/18] {systemd,udev}.pc: add names with underscores, deprecate the old ones The names with multiple lowercase words run together are hard to read. We started that way with very short names like rootprefix, but then same pattern was applied to longer and longer names. Looking at the body of .pc files available on my machine, many packages use underscores; let's do the same. Old names are kept for compatiblity, so this is backwards compatible. --- src/core/systemd.pc.in | 115 ++++++++++++++++++++++++++++++----------- src/udev/udev.pc.in | 3 +- 2 files changed, 88 insertions(+), 30 deletions(-) diff --git a/src/core/systemd.pc.in b/src/core/systemd.pc.in index 8331832c7a..da7e74ed7b 100644 --- a/src/core/systemd.pc.in +++ b/src/core/systemd.pc.in @@ -7,36 +7,93 @@ # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. +# Names with prefixes are prefered, and the run-together names should be +# considered deprecated (though there is no plan to remove them). New names +# shall have underscores. + prefix=@prefix@ -rootprefix=@rootprefix_noslash@ -sysconfdir=@sysconfdir@ -systemdutildir=${rootprefix}/lib/systemd -systemdsystemunitdir=${rootprefix}/lib/systemd/system -systemdsystempresetdir=${rootprefix}/lib/systemd/system-preset -systemduserunitdir=${prefix}/lib/systemd/user -systemduserpresetdir=${prefix}/lib/systemd/user-preset -systemdsystemconfdir=${sysconfdir}/systemd/system -systemduserconfdir=${sysconfdir}/systemd/user -systemdsystemunitpath=${systemdsystemconfdir}:/etc/systemd/system:/run/systemd/system:/usr/local/lib/systemd/system:${systemdsystemunitdir}:/usr/lib/systemd/system:/lib/systemd/system -systemduserunitpath=${systemduserconfdir}:/etc/systemd/user:/run/systemd/user:/usr/local/lib/systemd/user:/usr/local/share/systemd/user:${systemduserunitdir}:/usr/lib/systemd/user:/usr/share/systemd/user -systemdsystemgeneratordir=${rootprefix}/lib/systemd/system-generators -systemdusergeneratordir=${prefix}/lib/systemd/user-generators -systemdsystemgeneratorpath=/run/systemd/system-generators:/etc/systemd/system-generators:/usr/local/lib/systemd/system-generators:${systemdsystemgeneratordir} -systemdusergeneratorpath=/run/systemd/user-generators:/etc/systemd/user-generators:/usr/local/lib/systemd/user-generators:${systemdusergeneratordir} -systemdsleepdir=${rootprefix}/lib/systemd/system-sleep -systemdshutdowndir=${rootprefix}/lib/systemd/system-shutdown -tmpfilesdir=${prefix}/lib/tmpfiles.d -sysusersdir=${prefix}/lib/sysusers.d -sysctldir=${prefix}/lib/sysctl.d -binfmtdir=${prefix}/lib/binfmt.d -modulesloaddir=${prefix}/lib/modules-load.d -catalogdir=${prefix}/lib/systemd/catalog -systemuidmax=@systemuidmax@ -systemgidmax=@systemgidmax@ -dynamicuidmin=@dynamicuidmin@ -dynamicuidmax=@dynamicuidmax@ -containeruidbasemin=@containeruidbasemin@ -containeruidbasemax=@containeruidbasemax@ +root_prefix=@rootprefix_noslash@ +rootprefix=${root_prefix} +sysconf_dir=@sysconfdir@ +sysconfdir=${sysconf_dir} + +systemd_util_dir=${root_prefix}/lib/systemd +systemdutildir=${systemd_util_dir} + +systemd_system_unit_dir=${rootprefix}/lib/systemd/system +systemdsystemunitdir=${systemd_system_unit_dir} + +systemd_system_preset_dir=${rootprefix}/lib/systemd/system-preset +systemdsystempresetdir=${systemd_system_preset_dir} + +systemd_user_unit_dir=${prefix}/lib/systemd/user +systemduserunitdir=${systemd_user_unit_dir} + +systemd_user_preset_dir=${prefix}/lib/systemd/user-preset +systemduserpresetdir=${systemd_user_preset_dir} + +systemd_system_conf_dir=${sysconfdir}/systemd/system +systemdsystemconfdir=${systemd_system_conf_dir} + +systemd_user_conf_dir=${sysconfdir}/systemd/user +systemduserconfdir=${systemd_user_conf_dir} + +systemd_system_unit_path=${systemd_system_conf_dir}:/etc/systemd/system:/run/systemd/system:/usr/local/lib/systemd/system:${systemd_system_unit_dir}:/usr/lib/systemd/system:/lib/systemd/system +systemdsystemunitpath=${systemd_system_unit_path} + +systemd_user_unit_path=${systemd_user_conf_dir}:/etc/systemd/user:/run/systemd/user:/usr/local/lib/systemd/user:/usr/local/share/systemd/user:${systemd_user_unit_dir}:/usr/lib/systemd/user:/usr/share/systemd/user +systemduserunitpath=${systemd_user_unit_path} + +systemd_system_generator_dir=${root_prefix}/lib/systemd/system-generators +systemdsystemgeneratordir=${systemd_system_generator_dir} + +systemd_user_generator_dir=${prefix}/lib/systemd/user-generators +systemdusergeneratordir=${systemd_user_generator_dir} + +systemd_system_generator_path=/run/systemd/system-generators:/etc/systemd/system-generators:/usr/local/lib/systemd/system-generators:${systemd_system_generator_dir} +systemdsystemgeneratorpath=${systemd_system_generator_path} + +systemd_user_generator_path=/run/systemd/user-generators:/etc/systemd/user-generators:/usr/local/lib/systemd/user-generators:${systemd_user_generator_dir} +systemdusergeneratorpath=${systemd_user_generator_path} + +systemd_sleep_dir=${root_prefix}/lib/systemd/system-sleep +systemdsleepdir=${systemd_sleep_dir} + +systemd_shutdown_dir=${root_prefix}/lib/systemd/system-shutdown +systemdshutdowndir=${systemd_shutdown_dir} + +tmpfiles_dir=${prefix}/lib/tmpfiles.d +tmpfilesdir=${tmpfiles_dir} + +sysusers_dir=${prefix}/lib/sysusers.d +sysusersdir=${sysusers_dir} + +sysctl_dir=${prefix}/lib/sysctl.d +sysctldir=${sysctl_dir} + +binfmt_dir=${prefix}/lib/binfmt.d +binfmtdir=${binfmt_dir} + +modules_load_dir=${prefix}/lib/modules-load.d +modulesloaddir=${modules_load_dir} + +catalog_dir=${prefix}/lib/systemd/catalog +catalogdir=${catalog_dir} + +system_uid_max=@systemuidmax@ +systemuidmax=${system_uid_max} +system_gid_max=@systemgidmax@ +systemgidmax=${system_gid_max} + +dynamic_uid_min=@dynamicuidmin@ +dynamicuidmin=${dynamic_uid_min} +dynamic_uid_max=@dynamicuidmax@ +dynamicuidmax=${dynamic_uid_max} + +container_uid_base_min=@containeruidbasemin@ +containeruidbasemin=${container_uid_base_min} +container_uid_base_max=@containeruidbasemax@ +containeruidbasemax=${container_uid_base_max} Name: systemd Description: systemd System and Service Manager diff --git a/src/udev/udev.pc.in b/src/udev/udev.pc.in index 5acbb2d01a..7b4f4006b5 100644 --- a/src/udev/udev.pc.in +++ b/src/udev/udev.pc.in @@ -2,4 +2,5 @@ Name: udev Description: udev Version: @PROJECT_VERSION@ -udevdir=@udevlibexecdir@ +udev_dir=@udevlibexecdir@ +udevdir=${udev_dir} From d32014a5bba837a288286e0f06e1927786d06d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 23 Mar 2020 19:12:55 +0100 Subject: [PATCH 03/18] test-sd-path: basic test for the sd-path API --- src/test/meson.build | 4 +++ src/test/test-sd-path.c | 61 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/test/test-sd-path.c diff --git a/src/test/meson.build b/src/test/meson.build index 7c55f65be1..a8e81311f7 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -778,6 +778,10 @@ tests += [ [], []], + [['src/test/test-sd-path.c'], + [], + []], + [['src/test/test-local-addresses.c'], [], []], diff --git a/src/test/test-sd-path.c b/src/test/test-sd-path.c new file mode 100644 index 0000000000..780a62a2cf --- /dev/null +++ b/src/test/test-sd-path.c @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + +#include "sd-path.h" + +#include "alloc-util.h" +#include "string-util.h" +#include "strv.h" +#include "tests.h" + +static void test_sd_path_home(void) { + log_info("/* %s */", __func__); + + for (uint64_t i = 0; i < _SD_PATH_MAX; i++) { + _cleanup_free_ char *t, *s; + + assert_se(sd_path_home(i, NULL, &t) == 0); + assert_se(t); + log_info("%02"PRIu64": \"%s\"", i, t); + + assert_se(sd_path_home(i, "suffix", &s) == 0); + assert_se(s); + log_info("%02"PRIu64": \"%s\"", i, s); + assert_se(endswith(s, "/suffix")); + } + + char *tt; + assert_se(sd_path_home(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP); +} + +static void test_sd_path_search(void) { + log_info("/* %s */", __func__); + + for (uint64_t i = 0; i < _SD_PATH_MAX; i++) { + _cleanup_strv_free_ char **t, **s; + char **item; + + assert_se(sd_path_search(i, NULL, &t) == 0); + assert_se(t); + log_info("%02"PRIu64":", i); + STRV_FOREACH(item, t) + log_debug(" %s", *item); + + assert_se(sd_path_search(i, "suffix", &s) == 0); + assert_se(s); + log_info("%02"PRIu64":", i); + STRV_FOREACH(item, s) { + assert_se(endswith(*item, "/suffix")); + log_debug(" %s", *item); + } + } + + char *tt; + assert_se(sd_path_home(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP); +} + +int main(void) { + test_setup_logging(LOG_DEBUG); + + test_sd_path_home(); + test_sd_path_search(); +} From 51327bcc7457abb05cc80a5744fc233778a08ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 23 Mar 2020 19:50:59 +0100 Subject: [PATCH 04/18] sd-path: rename the two functions I think the two names were both pretty bad. They did not give a proper hint what the difference between the two functions is, and sd_path_home sounds like it is somehow related to /home or home directories or whatever, when in fact both functions return the same set of paths as either a colon-delimited string or a strv. "_strv" suffix is used by various functions in sd-bus, so let's reuse that. Those functions are not public yet, so let's rename. --- src/core/manager.c | 2 +- .../environment-d-generator.c | 2 +- src/libsystemd/sd-path/sd-path.c | 8 ++++---- src/path/path.c | 4 ++-- src/systemd/sd-path.h | 4 ++-- src/test/test-sd-path.c | 20 +++++++++---------- src/tmpfiles/tmpfiles.c | 2 +- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/core/manager.c b/src/core/manager.c index 38f7ba1eb8..4c59addfc8 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -689,7 +689,7 @@ static int manager_setup_prefix(Manager *m) { p = paths_user; for (i = 0; i < _EXEC_DIRECTORY_TYPE_MAX; i++) { - r = sd_path_home(p[i].type, p[i].suffix, &m->prefix[i]); + r = sd_path_lookup(p[i].type, p[i].suffix, &m->prefix[i]); if (r < 0) return r; } diff --git a/src/environment-d-generator/environment-d-generator.c b/src/environment-d-generator/environment-d-generator.c index 5fe51359f6..4a14c23f11 100644 --- a/src/environment-d-generator/environment-d-generator.c +++ b/src/environment-d-generator/environment-d-generator.c @@ -20,7 +20,7 @@ static int environment_dirs(char ***ret) { return -ENOMEM; /* ~/.config/systemd/environment.d */ - r = sd_path_home(SD_PATH_USER_CONFIGURATION, "environment.d", &c); + r = sd_path_lookup(SD_PATH_USER_CONFIGURATION, "environment.d", &c); if (r < 0) return r; diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c index 95d6551e5c..5797f55c75 100644 --- a/src/libsystemd/sd-path/sd-path.c +++ b/src/libsystemd/sd-path/sd-path.c @@ -323,7 +323,7 @@ static int get_path(uint64_t type, char **buffer, const char **ret) { return -EOPNOTSUPP; } -_public_ int sd_path_home(uint64_t type, const char *suffix, char **path) { +_public_ int sd_path_lookup(uint64_t type, const char *suffix, char **path) { _cleanup_free_ char *buffer = NULL; const char *ret; char *cc; @@ -343,7 +343,7 @@ _public_ int sd_path_home(uint64_t type, const char *suffix, char **path) { _cleanup_strv_free_ char **l = NULL; - r = sd_path_search(type, suffix, &l); + r = sd_path_lookup_strv(type, suffix, &l); if (r < 0) return r; @@ -550,7 +550,7 @@ static int get_search(uint64_t type, char ***list) { return -EOPNOTSUPP; } -_public_ int sd_path_search(uint64_t type, const char *suffix, char ***paths) { +_public_ int sd_path_lookup_strv(uint64_t type, const char *suffix, char ***paths) { char **i, **j; _cleanup_strv_free_ char **l = NULL, **n = NULL; int r; @@ -569,7 +569,7 @@ _public_ int sd_path_search(uint64_t type, const char *suffix, char ***paths) { char *p; - r = sd_path_home(type, suffix, &p); + r = sd_path_lookup(type, suffix, &p); if (r < 0) return r; diff --git a/src/path/path.c b/src/path/path.c index fa81632bb2..26252948c5 100644 --- a/src/path/path.c +++ b/src/path/path.c @@ -68,7 +68,7 @@ static int list_homes(void) { _cleanup_free_ char *p = NULL; int q; - q = sd_path_home(i, arg_suffix, &p); + q = sd_path_lookup(i, arg_suffix, &p); if (q == -ENXIO) continue; if (q < 0) { @@ -91,7 +91,7 @@ static int print_home(const char *n) { if (streq(path_table[i], n)) { _cleanup_free_ char *p = NULL; - r = sd_path_home(i, arg_suffix, &p); + r = sd_path_lookup(i, arg_suffix, &p); if (r < 0) return log_error_errno(r, "Failed to query %s: %m", n); diff --git a/src/systemd/sd-path.h b/src/systemd/sd-path.h index 16379876eb..2bb0b85244 100644 --- a/src/systemd/sd-path.h +++ b/src/systemd/sd-path.h @@ -81,8 +81,8 @@ enum { _SD_PATH_MAX, }; -int sd_path_home(uint64_t type, const char *suffix, char **path); -int sd_path_search(uint64_t type, const char *suffix, char ***paths); +int sd_path_lookup(uint64_t type, const char *suffix, char **path); +int sd_path_lookup_strv(uint64_t type, const char *suffix, char ***paths); _SD_END_DECLARATIONS; diff --git a/src/test/test-sd-path.c b/src/test/test-sd-path.c index 780a62a2cf..5888d3b9f9 100644 --- a/src/test/test-sd-path.c +++ b/src/test/test-sd-path.c @@ -7,40 +7,40 @@ #include "strv.h" #include "tests.h" -static void test_sd_path_home(void) { +static void test_sd_path_lookup(void) { log_info("/* %s */", __func__); for (uint64_t i = 0; i < _SD_PATH_MAX; i++) { _cleanup_free_ char *t, *s; - assert_se(sd_path_home(i, NULL, &t) == 0); + assert_se(sd_path_lookup(i, NULL, &t) == 0); assert_se(t); log_info("%02"PRIu64": \"%s\"", i, t); - assert_se(sd_path_home(i, "suffix", &s) == 0); + assert_se(sd_path_lookup(i, "suffix", &s) == 0); assert_se(s); log_info("%02"PRIu64": \"%s\"", i, s); assert_se(endswith(s, "/suffix")); } char *tt; - assert_se(sd_path_home(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP); + assert_se(sd_path_lookup(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP); } -static void test_sd_path_search(void) { +static void test_sd_path_lookup_strv(void) { log_info("/* %s */", __func__); for (uint64_t i = 0; i < _SD_PATH_MAX; i++) { _cleanup_strv_free_ char **t, **s; char **item; - assert_se(sd_path_search(i, NULL, &t) == 0); + assert_se(sd_path_lookup_strv(i, NULL, &t) == 0); assert_se(t); log_info("%02"PRIu64":", i); STRV_FOREACH(item, t) log_debug(" %s", *item); - assert_se(sd_path_search(i, "suffix", &s) == 0); + assert_se(sd_path_lookup_strv(i, "suffix", &s) == 0); assert_se(s); log_info("%02"PRIu64":", i); STRV_FOREACH(item, s) { @@ -50,12 +50,12 @@ static void test_sd_path_search(void) { } char *tt; - assert_se(sd_path_home(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP); + assert_se(sd_path_lookup(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP); } int main(void) { test_setup_logging(LOG_DEBUG); - test_sd_path_home(); - test_sd_path_search(); + test_sd_path_lookup(); + test_sd_path_lookup_strv(); } diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index d1ba5841fd..6ab30cdecf 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -244,7 +244,7 @@ static int specifier_directory(char specifier, const void *data, const void *use i = PTR_TO_UINT(data); assert(i < ELEMENTSOF(paths_system)); - return sd_path_home(paths[i].type, paths[i].suffix, ret); + return sd_path_lookup(paths[i].type, paths[i].suffix, ret); } static int log_unresolvable_specifier(const char *filename, unsigned line) { From 3919ecc55358815e2997d7212552251ffd478633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 23 Mar 2020 20:39:23 +0100 Subject: [PATCH 05/18] meson: run a no-op build to generate man rules When a new page is added using man/update-man-rules, ninja doesn't know about the new target until a build is initiated, so build/man/man and build/man/html would fail. Force a trivial build to regenerate the rules before calling 'ninja -t'. --- man/html.in | 3 +++ man/man.in | 3 +++ 2 files changed, 6 insertions(+) diff --git a/man/html.in b/man/html.in index bc9a668c23..c09d300d6f 100755 --- a/man/html.in +++ b/man/html.in @@ -6,6 +6,9 @@ if [ -z "$1" ]; then exit 1 fi +# make sure the rules have been regenrated (in case man/update-man-rules was just run) +ninja -C "@BUILD_ROOT@" version.h + target="man/$1.html" ninja -C "@BUILD_ROOT@" "$target" set -x diff --git a/man/man.in b/man/man.in index 75680b860c..812c6767fc 100755 --- a/man/man.in +++ b/man/man.in @@ -6,6 +6,9 @@ if [ -z "$1" ]; then exit 1 fi +# make sure the rules have been regenrated (in case man/update-man-rules was just run) +ninja -C "@BUILD_ROOT@" version.h + page="$(echo "$1" | sed 's/\./\\./')" target=$(ninja -C "@BUILD_ROOT@" -t query man/man | grep -E -m1 "man/$page\.[0-9]$" | awk '{print $2}') if [ -z "$target" ]; then From 557afad2b7d38f808f21524fda44fedebb5ad5ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 23 Mar 2020 20:37:47 +0100 Subject: [PATCH 06/18] libsystemd: install sd-path.h and export sd_path_lookup{,_strv} Those are not terribly imporant functions, but we have them, and there's no reason not to export them. --- src/libsystemd/libsystemd.sym | 6 ++++++ src/systemd/meson.build | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym index 8b6ebbcf8b..2c1bcab576 100644 --- a/src/libsystemd/libsystemd.sym +++ b/src/libsystemd/libsystemd.sym @@ -697,3 +697,9 @@ global: sd_event_source_send_child_signal; sd_journal_open_namespace; } LIBSYSTEMD_243; + +LIBSYSTEMD_246 { +global: + sd_path_lookup; + sd_path_lookup_strv; +} LIBSYSTEMD_245; diff --git a/src/systemd/meson.build b/src/systemd/meson.build index 05196554ac..63d0829b67 100644 --- a/src/systemd/meson.build +++ b/src/systemd/meson.build @@ -12,6 +12,7 @@ _systemd_headers = ''' sd-journal.h sd-login.h sd-messages.h + sd-path.h '''.split() # https://github.com/mesonbuild/meson/issues/1633 @@ -30,7 +31,6 @@ _not_installed_headers = ''' sd-ndisc.h sd-netlink.h sd-network.h - sd-path.h sd-radv.h sd-resolve.h sd-utf8.h From b35ed5530ba1c576b4fa899b9da04882a940ab07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 23 Mar 2020 20:36:41 +0100 Subject: [PATCH 07/18] man: add sd_path_lookup(3) --- man/path-documents.c | 9 ++ man/rules/meson.build | 1 + man/sd_path_lookup.xml | 182 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 man/path-documents.c create mode 100644 man/sd_path_lookup.xml diff --git a/man/path-documents.c b/man/path-documents.c new file mode 100644 index 0000000000..a6c1f9371a --- /dev/null +++ b/man/path-documents.c @@ -0,0 +1,9 @@ +#include +#include + +int main(void) { + char *t; + + sd_path_lookup(SD_PATH_USER_DOCUMENTS, NULL, &t); + printf("~/Documents: %s\n", t); +} diff --git a/man/rules/meson.build b/man/rules/meson.build index b95ef6964a..827fbd7155 100644 --- a/man/rules/meson.build +++ b/man/rules/meson.build @@ -623,6 +623,7 @@ manpages = [ '3', ['sd_notifyf', 'sd_pid_notify', 'sd_pid_notify_with_fds', 'sd_pid_notifyf'], ''], + ['sd_path_lookup', '3', ['sd_path_lookup_strv'], ''], ['sd_pid_get_owner_uid', '3', ['sd_peer_get_cgroup', diff --git a/man/sd_path_lookup.xml b/man/sd_path_lookup.xml new file mode 100644 index 0000000000..c14ccf0e8c --- /dev/null +++ b/man/sd_path_lookup.xml @@ -0,0 +1,182 @@ + + + + + + + + sd_path_lookup + systemd + + + + sd_path_lookup + 3 + + + + sd_path_lookup + sd_path_lookup_strv + + Query well-known file system paths + + + + + #include <systemd/sd-path.h> + + + + enum { + SD_PATH_TEMPORARY, + SD_PATH_TEMPORARY_LARGE, + + SD_PATH_SYSTEM_BINARIES, + SD_PATH_SYSTEM_INCLUDE, + SD_PATH_SYSTEM_LIBRARY_PRIVATE, + SD_PATH_SYSTEM_LIBRARY_ARCH, + SD_PATH_SYSTEM_SHARED, + SD_PATH_SYSTEM_CONFIGURATION_FACTORY, + SD_PATH_SYSTEM_STATE_FACTORY, + + SD_PATH_SYSTEM_CONFIGURATION, + SD_PATH_SYSTEM_RUNTIME, + SD_PATH_SYSTEM_RUNTIME_LOGS, + SD_PATH_SYSTEM_STATE_PRIVATE, + SD_PATH_SYSTEM_STATE_LOGS, + SD_PATH_SYSTEM_STATE_CACHE, + SD_PATH_SYSTEM_STATE_SPOOL, + + SD_PATH_USER_BINARIES, + SD_PATH_USER_LIBRARY_PRIVATE, + SD_PATH_USER_LIBRARY_ARCH, + SD_PATH_USER_SHARED, + + SD_PATH_USER_CONFIGURATION, + SD_PATH_USER_RUNTIME, + SD_PATH_USER_STATE_CACHE, + + SD_PATH_USER, + SD_PATH_USER_DOCUMENTS, + SD_PATH_USER_MUSIC, + SD_PATH_USER_PICTURES, + SD_PATH_USER_VIDEOS, + SD_PATH_USER_DOWNLOAD, + SD_PATH_USER_PUBLIC, + SD_PATH_USER_TEMPLATES, + SD_PATH_USER_DESKTOP, + + SD_PATH_SEARCH_BINARIES, + SD_PATH_SEARCH_BINARIES_DEFAULT, + SD_PATH_SEARCH_LIBRARY_PRIVATE, + SD_PATH_SEARCH_LIBRARY_ARCH, + SD_PATH_SEARCH_SHARED, + SD_PATH_SEARCH_CONFIGURATION_FACTORY, + SD_PATH_SEARCH_STATE_FACTORY, + SD_PATH_SEARCH_CONFIGURATION, +}; + + + int sd_path_lookup + uint64_t type + const char *suffix + char **paths + + + + int sd_path_lookup_strv + uint64_t type + const char *suffix + char ***paths + + + + + + Description + + sd_path_lookup() and sd_bus_path_lookup_strv() return a + single path or set of file system paths specified by the argument type. In case of + sd_path_lookup() a single NUL-terminated string is returned. + When type specifies a set of paths, they are concatenated using + : as a separator (as is traditionally done for e.g. $PATH or + $LD_LIBRARY_PATH). In case of sd_path_lookup_strv() a + NULL-terminated array of strings is returned (strv). If suffix + suffix is given, it is concatenated to each of the paths after a slash + (/). All returned paths are absolute. + + For paths which refer to user directories, the relevant XDG standard is followed, with support for + environment variables like $XDG_DOCUMENTS_DIR, $XDG_DESKTOP_DIR, + ..., and explicit configuration in /etc/xdg/user-dirs.conf or + ${XDG_CONFIG_HOME}/user-dirs.dirs. See + + XDG Base Directory Specification for details. + + systemd-path1 is + a wrapper around sd_path_lookup() and allows the same set of paths to be queried. + + + + + Return Value + + On success, sd_path_lookup() and sd_path_lookup_strv() + return a non-negative integer. On failure, a negative errno-style error number is returned by either + function. + + The returned string or string array (strv) must be + free3'd by the + caller. + + + Errors + + Returned errors may indicate the following problems: + + + + -EOPNOTSUPP + + Unknown identifier type. + + + + -EINVAL + + Output argument is NULL. + + + + -ENOMEM + + Memory allocation failed. + + + + + + + Examples + + + Look up the location of ~/Documents + + + Note that the default answer of $HOME/Documents may be + overridden by user-dirs.conf or + $XDG_DOCUMENTS_DIR. + + + + + + + See Also + + + systemd-path1 + + + + From a7addf32a529e56ee8a7f146042047884fa61b42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 24 Mar 2020 11:28:25 +0100 Subject: [PATCH 08/18] sd-path,strv: add simple helper to wrap oom handling around strv_split_nulstr() --- src/basic/strv.h | 10 ++++++++++ src/libsystemd/sd-path/sd-path.c | 11 +++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/basic/strv.h b/src/basic/strv.h index e7c2b1a604..dd3323c223 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -87,6 +87,16 @@ char **strv_parse_nulstr(const char *s, size_t l); char **strv_split_nulstr(const char *s); int strv_make_nulstr(char * const *l, char **p, size_t *n); +static inline int strv_from_nulstr(char ***a, const char *nulstr) { + char **t; + + t = strv_split_nulstr(nulstr); + if (!t) + return -ENOMEM; + *a = t; + return 0; +} + bool strv_overlap(char * const *a, char * const *b) _pure_; #define STRV_FOREACH(s, l) \ diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c index 5797f55c75..eed8229f5b 100644 --- a/src/libsystemd/sd-path/sd-path.c +++ b/src/libsystemd/sd-path/sd-path.c @@ -536,16 +536,11 @@ static int get_search(uint64_t type, char ***list) { "/etc", NULL); - case SD_PATH_SEARCH_BINARIES_DEFAULT: { - char **t; + case SD_PATH_SEARCH_BINARIES_DEFAULT: + return strv_from_nulstr(list, DEFAULT_PATH_NULSTR); - t = strv_split_nulstr(DEFAULT_PATH_NULSTR); - if (!t) - return -ENOMEM; - *list = t; - return 0; - }} + } return -EOPNOTSUPP; } From 385093b702d5950e7f7203405fc152206b8d77e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 24 Mar 2020 12:17:43 +0100 Subject: [PATCH 09/18] Split out generator directory setup to a src/core/generator-setup.c Those functions have only one non-test user, so we can move them to src/core/. --- src/core/generator-setup.c | 58 ++++++++++++++++++++++++++++++++++++++ src/core/generator-setup.h | 8 ++++++ src/core/manager.c | 1 + src/core/meson.build | 2 ++ src/shared/path-lookup.c | 54 ----------------------------------- src/shared/path-lookup.h | 5 ---- 6 files changed, 69 insertions(+), 59 deletions(-) create mode 100644 src/core/generator-setup.c create mode 100644 src/core/generator-setup.h diff --git a/src/core/generator-setup.c b/src/core/generator-setup.c new file mode 100644 index 0000000000..78ff590902 --- /dev/null +++ b/src/core/generator-setup.c @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + +#include + +#include "generator-setup.h" +#include "macro.h" +#include "mkdir.h" +#include "rm-rf.h" + +int lookup_paths_mkdir_generator(LookupPaths *p) { + int r, q; + + assert(p); + + if (!p->generator || !p->generator_early || !p->generator_late) + return -EINVAL; + + r = mkdir_p_label(p->generator, 0755); + + q = mkdir_p_label(p->generator_early, 0755); + if (q < 0 && r >= 0) + r = q; + + q = mkdir_p_label(p->generator_late, 0755); + if (q < 0 && r >= 0) + r = q; + + return r; +} + +void lookup_paths_trim_generator(LookupPaths *p) { + assert(p); + + /* Trim empty dirs */ + + if (p->generator) + (void) rmdir(p->generator); + if (p->generator_early) + (void) rmdir(p->generator_early); + if (p->generator_late) + (void) rmdir(p->generator_late); +} + +void lookup_paths_flush_generator(LookupPaths *p) { + assert(p); + + /* Flush the generated unit files in full */ + + if (p->generator) + (void) rm_rf(p->generator, REMOVE_ROOT|REMOVE_PHYSICAL); + if (p->generator_early) + (void) rm_rf(p->generator_early, REMOVE_ROOT|REMOVE_PHYSICAL); + if (p->generator_late) + (void) rm_rf(p->generator_late, REMOVE_ROOT|REMOVE_PHYSICAL); + + if (p->temporary_dir) + (void) rm_rf(p->temporary_dir, REMOVE_ROOT|REMOVE_PHYSICAL); +} diff --git a/src/core/generator-setup.h b/src/core/generator-setup.h new file mode 100644 index 0000000000..9688601a76 --- /dev/null +++ b/src/core/generator-setup.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +#pragma once + +#include "path-lookup.h" + +int lookup_paths_mkdir_generator(LookupPaths *p); +void lookup_paths_trim_generator(LookupPaths *p); +void lookup_paths_flush_generator(LookupPaths *p); diff --git a/src/core/manager.c b/src/core/manager.c index 4c59addfc8..148df8d523 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -44,6 +44,7 @@ #include "fd-util.h" #include "fileio.h" #include "fs-util.h" +#include "generator-setup.h" #include "hashmap.h" #include "install.h" #include "io-util.h" diff --git a/src/core/meson.build b/src/core/meson.build index 3586838f59..0b31bb79ed 100644 --- a/src/core/meson.build +++ b/src/core/meson.build @@ -72,6 +72,8 @@ libcore_sources = ''' emergency-action.h execute.c execute.h + generator-setup.c + generator-setup.h hostname-setup.c hostname-setup.h ima-setup.c diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c index 2707dce7a8..5e85b74a05 100644 --- a/src/shared/path-lookup.c +++ b/src/shared/path-lookup.c @@ -6,19 +6,15 @@ #include "alloc-util.h" #include "fs-util.h" -#include "install.h" #include "log.h" #include "macro.h" -#include "mkdir.h" #include "path-lookup.h" #include "path-util.h" -#include "rm-rf.h" #include "stat-util.h" #include "string-util.h" #include "strv.h" #include "tmpfile-util.h" #include "user-util.h" -#include "util.h" int xdg_user_runtime_dir(char **ret, const char *suffix) { const char *e; @@ -783,56 +779,6 @@ void lookup_paths_log(LookupPaths *p) { } } -int lookup_paths_mkdir_generator(LookupPaths *p) { - int r, q; - - assert(p); - - if (!p->generator || !p->generator_early || !p->generator_late) - return -EINVAL; - - r = mkdir_p_label(p->generator, 0755); - - q = mkdir_p_label(p->generator_early, 0755); - if (q < 0 && r >= 0) - r = q; - - q = mkdir_p_label(p->generator_late, 0755); - if (q < 0 && r >= 0) - r = q; - - return r; -} - -void lookup_paths_trim_generator(LookupPaths *p) { - assert(p); - - /* Trim empty dirs */ - - if (p->generator) - (void) rmdir(p->generator); - if (p->generator_early) - (void) rmdir(p->generator_early); - if (p->generator_late) - (void) rmdir(p->generator_late); -} - -void lookup_paths_flush_generator(LookupPaths *p) { - assert(p); - - /* Flush the generated unit files in full */ - - if (p->generator) - (void) rm_rf(p->generator, REMOVE_ROOT|REMOVE_PHYSICAL); - if (p->generator_early) - (void) rm_rf(p->generator_early, REMOVE_ROOT|REMOVE_PHYSICAL); - if (p->generator_late) - (void) rm_rf(p->generator_late, REMOVE_ROOT|REMOVE_PHYSICAL); - - if (p->temporary_dir) - (void) rm_rf(p->temporary_dir, REMOVE_ROOT|REMOVE_PHYSICAL); -} - char **generator_binary_paths(UnitFileScope scope) { bool append = false; /* Add items from SYSTEMD_GENERATOR_PATH before normal directories */ _cleanup_strv_free_ char **paths = NULL; diff --git a/src/shared/path-lookup.h b/src/shared/path-lookup.h index b99e918144..52f7a570a2 100644 --- a/src/shared/path-lookup.h +++ b/src/shared/path-lookup.h @@ -64,11 +64,6 @@ bool path_is_user_data_dir(const char *path); bool path_is_user_config_dir(const char *path); void lookup_paths_log(LookupPaths *p); - -int lookup_paths_mkdir_generator(LookupPaths *p); -void lookup_paths_trim_generator(LookupPaths *p); -void lookup_paths_flush_generator(LookupPaths *p); - void lookup_paths_free(LookupPaths *p); char **generator_binary_paths(UnitFileScope scope); From 09e6443ef454de24bdcb837a754433cd3c409437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 24 Mar 2020 12:21:41 +0100 Subject: [PATCH 10/18] Move path-lookup.c to src/basic I want to use it from sd-path later on so it needs to be moved out of src/shared (libsystemd is not allowed to use code from src/shared). --- src/basic/meson.build | 2 ++ src/{shared => basic}/path-lookup.c | 0 src/{shared => basic}/path-lookup.h | 0 src/shared/meson.build | 2 -- 4 files changed, 2 insertions(+), 2 deletions(-) rename src/{shared => basic}/path-lookup.c (100%) rename src/{shared => basic}/path-lookup.h (100%) diff --git a/src/basic/meson.build b/src/basic/meson.build index ccb22e1595..80ef6ff0ea 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -159,6 +159,8 @@ basic_sources = files(''' ordered-set.h parse-util.c parse-util.h + path-lookup.c + path-lookup.h path-util.c path-util.h prioq.c diff --git a/src/shared/path-lookup.c b/src/basic/path-lookup.c similarity index 100% rename from src/shared/path-lookup.c rename to src/basic/path-lookup.c diff --git a/src/shared/path-lookup.h b/src/basic/path-lookup.h similarity index 100% rename from src/shared/path-lookup.h rename to src/basic/path-lookup.h diff --git a/src/shared/meson.build b/src/shared/meson.build index 859c0bbfde..45a723f363 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -160,8 +160,6 @@ shared_sources = files(''' output-mode.h pager.c pager.h - path-lookup.c - path-lookup.h pe-header.h pkcs11-util.c pkcs11-util.h From ce7eb6aa84b24d411ede7ed570faba78ee084493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 24 Mar 2020 15:18:20 +0100 Subject: [PATCH 11/18] sd-path: simplify implementation of sd_path_lookup*() The two functions were duplicating a lot of functionality and more importantly, they both had explicit lists of types which are search paths. I want to add more types, and I don't want to have to remember to add them to both lists. --- src/libsystemd/sd-path/sd-path.c | 108 +++++++++++++------------------ 1 file changed, 45 insertions(+), 63 deletions(-) diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c index eed8229f5b..8bdc2435a3 100644 --- a/src/libsystemd/sd-path/sd-path.c +++ b/src/libsystemd/sd-path/sd-path.c @@ -323,59 +323,55 @@ static int get_path(uint64_t type, char **buffer, const char **ret) { return -EOPNOTSUPP; } -_public_ int sd_path_lookup(uint64_t type, const char *suffix, char **path) { +static int get_path_alloc(uint64_t type, const char *suffix, char **path) { _cleanup_free_ char *buffer = NULL; + char *buffer2 = NULL; const char *ret; - char *cc; int r; - assert_return(path, -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, - SD_PATH_SEARCH_CONFIGURATION_FACTORY, - SD_PATH_SEARCH_STATE_FACTORY, - SD_PATH_SEARCH_CONFIGURATION)) { - - _cleanup_strv_free_ char **l = NULL; - - r = sd_path_lookup_strv(type, suffix, &l); - if (r < 0) - return r; - - buffer = strv_join(l, ":"); - if (!buffer) - return -ENOMEM; - - *path = TAKE_PTR(buffer); - return 0; - } + assert(path); r = get_path(type, &buffer, &ret); if (r < 0) return r; - if (!suffix) { - if (!buffer) { - buffer = strdup(ret); - if (!buffer) - return -ENOMEM; - } - - *path = TAKE_PTR(buffer); - return 0; + if (suffix) { + suffix += strspn(suffix, "/"); + buffer2 = path_join(ret, suffix); + if (!buffer2) + return -ENOMEM; + } else if (!buffer) { + buffer = strdup(ret); + if (!buffer) + return -ENOMEM; } - suffix += strspn(suffix, "/"); - cc = path_join(ret, suffix); - if (!cc) + *path = buffer2 ?: TAKE_PTR(buffer); + return 0; +} + +_public_ int sd_path_lookup(uint64_t type, const char *suffix, char **path) { + int r; + + assert_return(path, -EINVAL); + + r = get_path_alloc(type, suffix, path); + if (r != -EOPNOTSUPP) + return r; + + /* Fall back to sd_path_lookup_strv */ + _cleanup_strv_free_ char **l = NULL; + char *buffer; + + r = sd_path_lookup_strv(type, suffix, &l); + if (r < 0) + return r; + + buffer = strv_join(l, ":"); + if (!buffer) return -ENOMEM; - *path = TAKE_PTR(cc); + *path = buffer; return 0; } @@ -546,43 +542,29 @@ static int get_search(uint64_t type, char ***list) { } _public_ int sd_path_lookup_strv(uint64_t type, const char *suffix, char ***paths) { - 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, - SD_PATH_SEARCH_CONFIGURATION_FACTORY, - SD_PATH_SEARCH_STATE_FACTORY, - SD_PATH_SEARCH_CONFIGURATION)) { + r = get_search(type, &l); + if (r == -EOPNOTSUPP) { + _cleanup_free_ char *t = NULL; - char *p; - - r = sd_path_lookup(type, suffix, &p); + r = get_path_alloc(type, suffix, &t); if (r < 0) return r; l = new(char*, 2); - if (!l) { - free(p); + if (!l) return -ENOMEM; - } - - l[0] = p; + l[0] = TAKE_PTR(t); l[1] = NULL; *paths = TAKE_PTR(l); return 0; - } - r = get_search(type, &l); - if (r < 0) + } else if (r < 0) return r; if (!suffix) { @@ -594,7 +576,7 @@ _public_ int sd_path_lookup_strv(uint64_t type, const char *suffix, char ***path if (!n) return -ENOMEM; - j = n; + char **i, **j = n; STRV_FOREACH(i, l) { *j = path_join(*i, suffix); if (!*j) @@ -602,8 +584,8 @@ _public_ int sd_path_lookup_strv(uint64_t type, const char *suffix, char ***path j++; } - *j = NULL; + *paths = TAKE_PTR(n); return 0; } From 9c5bb2033db0c0927593b929ff760b69295a9f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 24 Mar 2020 16:04:50 +0100 Subject: [PATCH 12/18] 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. --- man/sd_path_lookup.xml | 23 ++++++++ src/libsystemd/sd-path/sd-path.c | 97 ++++++++++++++++++++++++++++++++ src/path/path.c | 23 ++++++++ src/systemd/sd-path.h | 24 ++++++++ 4 files changed, 167 insertions(+) diff --git a/man/sd_path_lookup.xml b/man/sd_path_lookup.xml index c14ccf0e8c..81812bc003 100644 --- a/man/sd_path_lookup.xml +++ b/man/sd_path_lookup.xml @@ -75,6 +75,29 @@ SD_PATH_SEARCH_CONFIGURATION_FACTORY, SD_PATH_SEARCH_STATE_FACTORY, SD_PATH_SEARCH_CONFIGURATION, + + SD_PATH_SYSTEMD_UTIL_DIR, + SD_PATH_SYSTEMD_SYSTEM_UNIT_DIR, + SD_PATH_SYSTEMD_SYSTEM_PRESET_DIR, + SD_PATH_SYSTEMD_USER_UNIT_DIR, + SD_PATH_SYSTEMD_USER_PRESET_DIR, + SD_PATH_SYSTEMD_SYSTEM_CONF_DIR, + SD_PATH_SYSTEMD_USER_CONF_DIR, + SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH, + SD_PATH_SYSTEMD_USER_UNIT_PATH, + SD_PATH_SYSTEMD_SYSTEM_GENERATOR_DIR, + SD_PATH_SYSTEMD_USER_GENERATOR_DIR, + SD_PATH_SYSTEMD_SYSTEM_GENERATOR_PATH, + SD_PATH_SYSTEMD_USER_GENERATOR_PATH, + SD_PATH_SYSTEMD_SLEEP_DIR, + SD_PATH_SYSTEMD_SHUTDOWN_DIR, + + SD_PATH_TMPFILES_DIR, + SD_PATH_SYSUSERS_DIR, + SD_PATH_SYSCTL_DIR, + SD_PATH_BINFMT_DIR, + SD_PATH_MODULES_LOAD_DIR, + SD_PATH_CATALOG_DIR, }; 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; } diff --git a/src/path/path.c b/src/path/path.c index 26252948c5..aefdae1d51 100644 --- a/src/path/path.c +++ b/src/path/path.c @@ -58,6 +58,29 @@ static const char* const path_table[_SD_PATH_MAX] = { [SD_PATH_SEARCH_CONFIGURATION_FACTORY] = "search-configuration-factory", [SD_PATH_SEARCH_STATE_FACTORY] = "search-state-factory", [SD_PATH_SEARCH_CONFIGURATION] = "search-configuration", + + [SD_PATH_SYSTEMD_UTIL_DIR] = "systemd-util-dir", + [SD_PATH_SYSTEMD_SYSTEM_UNIT_DIR] = "systemd-system-unit-dir", + [SD_PATH_SYSTEMD_SYSTEM_PRESET_DIR] = "systemd-system-preset-dir", + [SD_PATH_SYSTEMD_USER_UNIT_DIR] = "systemd-user-unit-dir", + [SD_PATH_SYSTEMD_USER_PRESET_DIR] = "systemd-user-preset-dir", + [SD_PATH_SYSTEMD_SYSTEM_CONF_DIR] = "systemd-system-conf-dir", + [SD_PATH_SYSTEMD_USER_CONF_DIR] = "systemd-user-conf-dir", + [SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH] = "systemd-system-unit-path", + [SD_PATH_SYSTEMD_USER_UNIT_PATH] = "systemd-user-unit-path", + [SD_PATH_SYSTEMD_SYSTEM_GENERATOR_DIR] = "systemd-system-generator-dir", + [SD_PATH_SYSTEMD_USER_GENERATOR_DIR] = "systemd-user-generator-dir", + [SD_PATH_SYSTEMD_SYSTEM_GENERATOR_PATH] = "systemd-system-generator-path", + [SD_PATH_SYSTEMD_USER_GENERATOR_PATH] = "systemd-user-generator-path", + [SD_PATH_SYSTEMD_SLEEP_DIR] = "systemd-sleep-dir", + [SD_PATH_SYSTEMD_SHUTDOWN_DIR] = "systemd-shutdown-dir", + + [SD_PATH_TMPFILES_DIR] = "tmpfiles-dir", + [SD_PATH_SYSUSERS_DIR] = "sysusers-dir", + [SD_PATH_SYSCTL_DIR] = "sysctl-dir", + [SD_PATH_BINFMT_DIR] = "binfmt-dir", + [SD_PATH_MODULES_LOAD_DIR] = "modules-load-dir", + [SD_PATH_CATALOG_DIR] = "catalog-dir", }; static int list_homes(void) { diff --git a/src/systemd/sd-path.h b/src/systemd/sd-path.h index 2bb0b85244..203f01dd90 100644 --- a/src/systemd/sd-path.h +++ b/src/systemd/sd-path.h @@ -78,6 +78,30 @@ enum { SD_PATH_SEARCH_STATE_FACTORY, SD_PATH_SEARCH_CONFIGURATION, + /* Various systemd paths, generally mirroring systemd.pc */ + SD_PATH_SYSTEMD_UTIL_DIR, + SD_PATH_SYSTEMD_SYSTEM_UNIT_DIR, + SD_PATH_SYSTEMD_SYSTEM_PRESET_DIR, + SD_PATH_SYSTEMD_USER_UNIT_DIR, + SD_PATH_SYSTEMD_USER_PRESET_DIR, + SD_PATH_SYSTEMD_SYSTEM_CONF_DIR, + SD_PATH_SYSTEMD_USER_CONF_DIR, + SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH, + SD_PATH_SYSTEMD_USER_UNIT_PATH, + SD_PATH_SYSTEMD_SYSTEM_GENERATOR_DIR, + SD_PATH_SYSTEMD_USER_GENERATOR_DIR, + SD_PATH_SYSTEMD_SYSTEM_GENERATOR_PATH, + SD_PATH_SYSTEMD_USER_GENERATOR_PATH, + SD_PATH_SYSTEMD_SLEEP_DIR, + SD_PATH_SYSTEMD_SHUTDOWN_DIR, + + SD_PATH_TMPFILES_DIR, + SD_PATH_SYSUSERS_DIR, + SD_PATH_SYSCTL_DIR, + SD_PATH_BINFMT_DIR, + SD_PATH_MODULES_LOAD_DIR, + SD_PATH_CATALOG_DIR, + _SD_PATH_MAX, }; From 96d33e4ac0ba9fa42f4ec8379d8decf1c722197d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 24 Mar 2020 16:28:26 +0100 Subject: [PATCH 13/18] Rename _PATH variables to _DIR when they refer to a directory We were very inconsistent in this, but in general _PATH signifies a search path (separated with :), and _DIR signifies a single directory. --- man/custom-entities.ent.in | 8 +-- meson.build | 14 ++--- src/basic/path-lookup.c | 22 +++---- src/libsystemd/sd-path/sd-path.c | 10 +-- src/test/test-install-root.c | 102 +++++++++++++++---------------- 5 files changed, 78 insertions(+), 78 deletions(-) diff --git a/man/custom-entities.ent.in b/man/custom-entities.ent.in index 85805777a0..84a29f5de4 100644 --- a/man/custom-entities.ent.in +++ b/man/custom-entities.ent.in @@ -1,10 +1,10 @@ - - - - + + + + diff --git a/meson.build b/meson.build index d6c09cb18a..a8d6b5beee 100644 --- a/meson.build +++ b/meson.build @@ -196,7 +196,7 @@ memory_accounting_default = get_option('memory-accounting-default') status_unit_format_default = get_option('status-unit-format-default') conf.set_quoted('PKGSYSCONFDIR', pkgsysconfdir) -conf.set_quoted('SYSTEM_CONFIG_UNIT_PATH', join_paths(pkgsysconfdir, 'system')) +conf.set_quoted('SYSTEM_CONFIG_UNIT_DIR', join_paths(pkgsysconfdir, 'system')) conf.set_quoted('SYSTEM_DATA_UNIT_PATH', systemunitdir) conf.set_quoted('SYSTEM_SYSVINIT_PATH', sysvinit_path) conf.set_quoted('SYSTEM_SYSVRCND_PATH', sysvrcnd_path) @@ -204,8 +204,8 @@ conf.set_quoted('RC_LOCAL_SCRIPT_PATH_START', get_option('rc-loc conf.set('ANSI_OK_COLOR', 'ANSI_' + get_option('ok-color').underscorify().to_upper()) -conf.set_quoted('USER_CONFIG_UNIT_PATH', join_paths(pkgsysconfdir, 'user')) -conf.set_quoted('USER_DATA_UNIT_PATH', userunitdir) +conf.set_quoted('USER_CONFIG_UNIT_DIR', join_paths(pkgsysconfdir, 'user')) +conf.set_quoted('USER_DATA_UNIT_DIR', userunitdir) conf.set_quoted('CERTIFICATE_ROOT', get_option('certificate-root')) conf.set_quoted('CATALOG_DATABASE', join_paths(catalogstatedir, 'database')) conf.set_quoted('SYSTEMD_CGROUP_AGENT_PATH', join_paths(rootlibexecdir, 'systemd-cgroups-agent')) @@ -221,10 +221,10 @@ conf.set_quoted('ROOTPREFIX', rootprefixdir) conf.set_quoted('RANDOM_SEED_DIR', randomseeddir) conf.set_quoted('RANDOM_SEED', join_paths(randomseeddir, 'random-seed')) conf.set_quoted('SYSTEMD_CRYPTSETUP_PATH', join_paths(rootlibexecdir, 'systemd-cryptsetup')) -conf.set_quoted('SYSTEM_GENERATOR_PATH', systemgeneratordir) -conf.set_quoted('USER_GENERATOR_PATH', usergeneratordir) -conf.set_quoted('SYSTEM_ENV_GENERATOR_PATH', systemenvgeneratordir) -conf.set_quoted('USER_ENV_GENERATOR_PATH', userenvgeneratordir) +conf.set_quoted('SYSTEM_GENERATOR_DIR', systemgeneratordir) +conf.set_quoted('USER_GENERATOR_DIR', usergeneratordir) +conf.set_quoted('SYSTEM_ENV_GENERATOR_DIR', systemenvgeneratordir) +conf.set_quoted('USER_ENV_GENERATOR_DIR', userenvgeneratordir) conf.set_quoted('SYSTEM_SHUTDOWN_PATH', systemshutdowndir) conf.set_quoted('SYSTEM_SLEEP_PATH', systemsleepdir) conf.set_quoted('SYSTEMD_KBD_MODEL_MAP', join_paths(pkgdatadir, 'kbd-model-map')) diff --git a/src/basic/path-lookup.c b/src/basic/path-lookup.c index 5e85b74a05..52968dee34 100644 --- a/src/basic/path-lookup.c +++ b/src/basic/path-lookup.c @@ -96,14 +96,14 @@ int xdg_user_data_dir(char **ret, const char *suffix) { static const char* const user_data_unit_paths[] = { "/usr/local/lib/systemd/user", "/usr/local/share/systemd/user", - USER_DATA_UNIT_PATH, + USER_DATA_UNIT_DIR, "/usr/lib/systemd/user", "/usr/share/systemd/user", NULL }; static const char* const user_config_unit_paths[] = { - USER_CONFIG_UNIT_PATH, + USER_CONFIG_UNIT_DIR, "/etc/systemd/user", NULL }; @@ -321,12 +321,12 @@ static int acquire_config_dirs(UnitFileScope scope, char **persistent, char **ru switch (scope) { case UNIT_FILE_SYSTEM: - a = strdup(SYSTEM_CONFIG_UNIT_PATH); + a = strdup(SYSTEM_CONFIG_UNIT_DIR); b = strdup("/run/systemd/system"); break; case UNIT_FILE_GLOBAL: - a = strdup(USER_CONFIG_UNIT_PATH); + a = strdup(USER_CONFIG_UNIT_DIR); b = strdup("/run/systemd/user"); break; @@ -614,7 +614,7 @@ int lookup_paths_init( STRV_IFNOTNULL(transient), STRV_IFNOTNULL(generator_early), persistent_config, - SYSTEM_CONFIG_UNIT_PATH, + SYSTEM_CONFIG_UNIT_DIR, "/etc/systemd/system", STRV_IFNOTNULL(persistent_attached), runtime_config, @@ -638,7 +638,7 @@ int lookup_paths_init( STRV_IFNOTNULL(transient), STRV_IFNOTNULL(generator_early), persistent_config, - USER_CONFIG_UNIT_PATH, + USER_CONFIG_UNIT_DIR, "/etc/systemd/user", runtime_config, "/run/systemd/user", @@ -646,7 +646,7 @@ int lookup_paths_init( "/usr/local/share/systemd/user", "/usr/share/systemd/user", "/usr/local/lib/systemd/user", - USER_DATA_UNIT_PATH, + USER_DATA_UNIT_DIR, "/usr/lib/systemd/user", STRV_IFNOTNULL(generator_late)); break; @@ -798,7 +798,7 @@ char **generator_binary_paths(UnitFileScope scope) { add = strv_new("/run/systemd/system-generators", "/etc/systemd/system-generators", "/usr/local/lib/systemd/system-generators", - SYSTEM_GENERATOR_PATH); + SYSTEM_GENERATOR_DIR); break; case UNIT_FILE_GLOBAL: @@ -806,7 +806,7 @@ char **generator_binary_paths(UnitFileScope scope) { add = strv_new("/run/systemd/user-generators", "/etc/systemd/user-generators", "/usr/local/lib/systemd/user-generators", - USER_GENERATOR_PATH); + USER_GENERATOR_DIR); break; default: @@ -845,12 +845,12 @@ char **env_generator_binary_paths(bool is_system) { add = strv_new("/run/systemd/system-environment-generators", "/etc/systemd/system-environment-generators", "/usr/local/lib/systemd/system-environment-generators", - SYSTEM_ENV_GENERATOR_PATH); + SYSTEM_ENV_GENERATOR_DIR); else add = strv_new("/run/systemd/user-environment-generators", "/etc/systemd/user-environment-generators", "/usr/local/lib/systemd/user-environment-generators", - USER_ENV_GENERATOR_PATH); + USER_ENV_GENERATOR_DIR); if (!add) return NULL; diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c index edc32fbd87..4fd96fb5a2 100644 --- a/src/libsystemd/sd-path/sd-path.c +++ b/src/libsystemd/sd-path/sd-path.c @@ -333,7 +333,7 @@ static int get_path(uint64_t type, char **buffer, const char **ret) { return 0; case SD_PATH_SYSTEMD_USER_UNIT_DIR: - *ret = USER_DATA_UNIT_PATH; + *ret = USER_DATA_UNIT_DIR; return 0; case SD_PATH_SYSTEMD_USER_PRESET_DIR: @@ -341,19 +341,19 @@ static int get_path(uint64_t type, char **buffer, const char **ret) { return 0; case SD_PATH_SYSTEMD_SYSTEM_CONF_DIR: - *ret = SYSTEM_CONFIG_UNIT_PATH; // FIXME: _DIR vs. _PATH + *ret = SYSTEM_CONFIG_UNIT_DIR; return 0; case SD_PATH_SYSTEMD_USER_CONF_DIR: - *ret = USER_CONFIG_UNIT_PATH; // FIXME: _DIR vs. _PATH + *ret = USER_CONFIG_UNIT_DIR; return 0; case SD_PATH_SYSTEMD_SYSTEM_GENERATOR_DIR: - *ret = SYSTEM_GENERATOR_PATH; // FIXME: _DIR vs. _PATH + *ret = SYSTEM_GENERATOR_DIR; return 0; case SD_PATH_SYSTEMD_USER_GENERATOR_DIR: - *ret = USER_GENERATOR_PATH; // FIXME: _DIR vs. _PATH + *ret = USER_GENERATOR_DIR; return 0; case SD_PATH_SYSTEMD_SLEEP_DIR: diff --git a/src/test/test-install-root.c b/src/test/test-install-root.c index 25498916f1..49faa6a33b 100644 --- a/src/test/test-install-root.c +++ b/src/test/test-install-root.c @@ -55,7 +55,7 @@ static void test_basic_mask_and_enable(const char *root) { assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/dev/null")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/a.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/a.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); @@ -74,7 +74,7 @@ static void test_basic_mask_and_enable(const char *root) { assert_se(unit_file_unmask(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_UNLINK); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/a.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/a.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -83,7 +83,7 @@ static void test_basic_mask_and_enable(const char *root) { assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/a.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/a.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -102,7 +102,7 @@ static void test_basic_mask_and_enable(const char *root) { assert_se(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_UNLINK); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/a.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -123,7 +123,7 @@ static void test_basic_mask_and_enable(const char *root) { assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/a.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/a.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -138,7 +138,7 @@ static void test_basic_mask_and_enable(const char *root) { assert_se(unit_file_reenable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("b.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 2); assert_se(changes[0].type == UNIT_FILE_UNLINK); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/a.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/a.service"); assert_se(streq(changes[0].path, p)); assert_se(changes[1].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[1].source, "/usr/lib/systemd/system/a.service")); @@ -196,7 +196,7 @@ static void test_linked_units(const char *root) { p = strjoina(root, "/usr/lib/systemd/system/linked2.service"); assert_se(symlink("/opt/linked2.service", p) >= 0); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked3.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked3.service"); assert_se(symlink("/opt/linked3.service", p) >= 0); assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked.service", &state) == -ENOENT); @@ -208,7 +208,7 @@ static void test_linked_units(const char *root) { assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/opt/linked.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -219,7 +219,7 @@ static void test_linked_units(const char *root) { assert_se(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("linked.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_UNLINK); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -229,8 +229,8 @@ static void test_linked_units(const char *root) { /* Now, let's not just link it, but also enable it */ assert_se(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("/opt/linked.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 2); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/linked.service"); - q = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/linked.service"); + q = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service"); for (i = 0 ; i < n_changes; i++) { assert_se(changes[i].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[i].source, "/opt/linked.service")); @@ -251,8 +251,8 @@ static void test_linked_units(const char *root) { /* And let's unlink it again */ assert_se(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("linked.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 2); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/linked.service"); - q = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/linked.service"); + q = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked.service"); for (i = 0; i < n_changes; i++) { assert_se(changes[i].type == UNIT_FILE_UNLINK); @@ -271,8 +271,8 @@ static void test_linked_units(const char *root) { assert_se(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("linked2.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 2); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/linked2.service"); - q = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked2.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/linked2.service"); + q = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/linked2.service"); for (i = 0 ; i < n_changes; i++) { assert_se(changes[i].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[i].source, "/opt/linked2.service")); @@ -325,7 +325,7 @@ static void test_default(const char *root) { assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/test-default-real.target")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH "/" SPECIAL_DEFAULT_TARGET); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR "/" SPECIAL_DEFAULT_TARGET); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -355,7 +355,7 @@ static void test_add_dependency(const char *root) { assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/real-add-dependency-test-service.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/real-add-dependency-test-target.target.wants/real-add-dependency-test-service.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/real-add-dependency-test-target.target.wants/real-add-dependency-test-service.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -396,7 +396,7 @@ static void test_template_enable(const char *root) { assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/template@def.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/template@def.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -427,7 +427,7 @@ static void test_template_enable(const char *root) { assert_se(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("template@foo.service"), &changes, &n_changes) >= 0); assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/template@foo.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/template@foo.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -460,7 +460,7 @@ static void test_template_enable(const char *root) { assert_se(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("template-symlink@quux.service"), &changes, &n_changes) >= 0); assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/template@quux.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/template@quux.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -506,7 +506,7 @@ static void test_indirect(const char *root) { assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/indirectb.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/indirectb.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/indirectb.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -518,7 +518,7 @@ static void test_indirect(const char *root) { assert_se(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("indirectc.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_UNLINK); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/indirectb.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/indirectb.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -559,7 +559,7 @@ static void test_preset_and_list(const char *root) { assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/preset-yes.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/preset-yes.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/preset-yes.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -570,7 +570,7 @@ static void test_preset_and_list(const char *root) { assert_se(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("preset-yes.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_UNLINK); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/preset-yes.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/preset-yes.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -590,7 +590,7 @@ static void test_preset_and_list(const char *root) { assert_se(n_changes > 0); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/preset-yes.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/preset-yes.service"); for (i = 0; i < n_changes; i++) { @@ -655,7 +655,7 @@ static void test_revert(const char *root) { unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/xx.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/xx.service"); assert_se(write_string_file(p, "# Empty override\n", WRITE_STRING_FILE_CREATE) >= 0); /* Revert the override file */ @@ -666,7 +666,7 @@ static void test_revert(const char *root) { unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/xx.service.d/dropin.conf"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/xx.service.d/dropin.conf"); assert_se(mkdir_parents(p, 0755) >= 0); assert_se(write_string_file(p, "# Empty dropin\n", WRITE_STRING_FILE_CREATE) >= 0); @@ -676,7 +676,7 @@ static void test_revert(const char *root) { assert_se(changes[0].type == UNIT_FILE_UNLINK); assert_se(streq(changes[0].path, p)); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/xx.service.d"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/xx.service.d"); assert_se(changes[1].type == UNIT_FILE_UNLINK); assert_se(streq(changes[1].path, p)); unit_file_changes_free(changes, n_changes); @@ -715,7 +715,7 @@ static void test_preset_order(const char *root) { assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/prefix-1.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/prefix-1.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/prefix-1.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -777,7 +777,7 @@ static void test_with_dropin(const char *root) { assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "with-dropin-1.service", &state) >= 0 && state == UNIT_FILE_DISABLED); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/with-dropin-2.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/with-dropin-2.service"); assert_se(write_string_file(p, "[Install]\n" "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0); @@ -795,7 +795,7 @@ static void test_with_dropin(const char *root) { "[Install]\n" "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/with-dropin-3.service.d/dropin.conf"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/with-dropin-3.service.d/dropin.conf"); assert_se(mkdir_parents(p, 0755) >= 0); assert_se(write_string_file(p, "[Install]\n" @@ -808,7 +808,7 @@ static void test_with_dropin(const char *root) { "[Install]\n" "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/with-dropin-4a.service.d/dropin.conf"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/with-dropin-4a.service.d/dropin.conf"); assert_se(mkdir_parents(p, 0755) >= 0); assert_se(write_string_file(p, "[Install]\n" @@ -829,9 +829,9 @@ static void test_with_dropin(const char *root) { assert_se(changes[1].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-1.service")); assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-1.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-1.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-1.service"); assert_se(streq(changes[0].path, p)); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/graphical.target.wants/with-dropin-1.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/graphical.target.wants/with-dropin-1.service"); assert_se(streq(changes[1].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -841,11 +841,11 @@ static void test_with_dropin(const char *root) { assert_se(n_changes == 2); assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(changes[1].type == UNIT_FILE_SYMLINK); - assert_se(streq(changes[0].source, SYSTEM_CONFIG_UNIT_PATH"/with-dropin-2.service")); - assert_se(streq(changes[1].source, SYSTEM_CONFIG_UNIT_PATH"/with-dropin-2.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-2.service"); + assert_se(streq(changes[0].source, SYSTEM_CONFIG_UNIT_DIR"/with-dropin-2.service")); + assert_se(streq(changes[1].source, SYSTEM_CONFIG_UNIT_DIR"/with-dropin-2.service")); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-2.service"); assert_se(streq(changes[0].path, p)); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/graphical.target.wants/with-dropin-2.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/graphical.target.wants/with-dropin-2.service"); assert_se(streq(changes[1].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -857,9 +857,9 @@ static void test_with_dropin(const char *root) { assert_se(changes[1].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-3.service")); assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-3.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-3.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-3.service"); assert_se(streq(changes[0].path, p)); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/graphical.target.wants/with-dropin-3.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/graphical.target.wants/with-dropin-3.service"); assert_se(streq(changes[1].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -871,9 +871,9 @@ static void test_with_dropin(const char *root) { assert_se(changes[1].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-4a.service")); assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-4b.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-4a.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-4a.service"); assert_se(streq(changes[0].path, p)); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-4b.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-4b.service"); assert_se(streq(changes[1].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -941,9 +941,9 @@ static void test_with_dropin_template(const char *root) { assert_se(changes[1].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-1@.service")); assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-1@.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-1@instance-1.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-1@instance-1.service"); assert_se(streq(changes[0].path, p)); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/graphical.target.wants/with-dropin-1@instance-1.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/graphical.target.wants/with-dropin-1@instance-1.service"); assert_se(streq(changes[1].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -954,9 +954,9 @@ static void test_with_dropin_template(const char *root) { assert_se(changes[1].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-2@.service")); assert_se(streq(changes[1].source, "/usr/lib/systemd/system/with-dropin-2@.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-2@instance-1.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-2@instance-1.service"); assert_se(streq(changes[0].path, p)); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/graphical.target.wants/with-dropin-2@instance-1.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/graphical.target.wants/with-dropin-2@instance-1.service"); assert_se(streq(changes[1].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -965,7 +965,7 @@ static void test_with_dropin_template(const char *root) { assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-2@.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-2@instance-2.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-2@instance-2.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -974,7 +974,7 @@ static void test_with_dropin_template(const char *root) { assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_SYMLINK); assert_se(streq(changes[0].source, "/usr/lib/systemd/system/with-dropin-3@.service")); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/with-dropin-3@instance-2.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/with-dropin-3@instance-2.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -1014,7 +1014,7 @@ static void test_preset_multiple_instances(const char *root) { assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "foo@bar0.service", &state) >= 0 && state == UNIT_FILE_ENABLED); assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_SYMLINK); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/foo@bar0.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/foo@bar0.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -1022,7 +1022,7 @@ static void test_preset_multiple_instances(const char *root) { assert_se(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("foo@bar0.service"), &changes, &n_changes) >= 0); assert_se(n_changes == 1); assert_se(changes[0].type == UNIT_FILE_UNLINK); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/foo@bar0.service"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/multi-user.target.wants/foo@bar0.service"); assert_se(streq(changes[0].path, p)); unit_file_changes_free(changes, n_changes); changes = NULL; n_changes = 0; @@ -1214,7 +1214,7 @@ int main(int argc, char *argv[]) { p = strjoina(root, "/usr/lib/systemd/system/"); assert_se(mkdir_p(p, 0755) >= 0); - p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/"); + p = strjoina(root, SYSTEM_CONFIG_UNIT_DIR"/"); assert_se(mkdir_p(p, 0755) >= 0); p = strjoina(root, "/run/systemd/system/"); From b0c82192604c2e21e7d1beab23855111a8213b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 24 Mar 2020 17:02:11 +0100 Subject: [PATCH 14/18] network: move NETWORK_DIRS to path-lookup.h In preparation for future changes... --- src/basic/path-lookup.h | 3 +++ src/libsystemd-network/network-internal.h | 3 --- src/network/netdev/netdev.c | 1 + src/network/networkd-manager.c | 1 + src/network/networkd-network.c | 1 + src/udev/net/link-config.c | 1 + 6 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/basic/path-lookup.h b/src/basic/path-lookup.h index 52f7a570a2..f67b8d416a 100644 --- a/src/basic/path-lookup.h +++ b/src/basic/path-lookup.h @@ -5,6 +5,7 @@ typedef struct LookupPaths LookupPaths; +#include "def.h" #include "unit-file.h" #include "macro.h" @@ -68,3 +69,5 @@ void lookup_paths_free(LookupPaths *p); char **generator_binary_paths(UnitFileScope scope); char **env_generator_binary_paths(bool is_system); + +#define NETWORK_DIRS ((const char* const*) CONF_PATHS_STRV("systemd/network")) diff --git a/src/libsystemd-network/network-internal.h b/src/libsystemd-network/network-internal.h index 593bad2230..16ff173ac6 100644 --- a/src/libsystemd-network/network-internal.h +++ b/src/libsystemd-network/network-internal.h @@ -8,7 +8,6 @@ #include "sd-dhcp-lease.h" #include "conf-parser.h" -#include "def.h" #include "set.h" #include "strv.h" @@ -66,5 +65,3 @@ int deserialize_dhcp_routes(struct sd_dhcp_route **ret, size_t *ret_size, size_t /* It is not necessary to add deserialize_dhcp_option(). Use unhexmem() instead. */ int serialize_dhcp_option(FILE *f, const char *key, const void *data, size_t size); - -#define NETWORK_DIRS ((const char* const*) CONF_PATHS_STRV("systemd/network")) diff --git a/src/network/netdev/netdev.c b/src/network/netdev/netdev.c index f8121a48ed..bc85d4babb 100644 --- a/src/network/netdev/netdev.c +++ b/src/network/netdev/netdev.c @@ -24,6 +24,7 @@ #include "network-internal.h" #include "networkd-manager.h" #include "nlmon.h" +#include "path-lookup.h" #include "siphash24.h" #include "stat-util.h" #include "string-table.h" diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 804f33d6cb..0872b7301b 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -30,6 +30,7 @@ #include "networkd-network-bus.h" #include "networkd-speed-meter.h" #include "ordered-set.h" +#include "path-lookup.h" #include "path-util.h" #include "set.h" #include "signal-util.h" diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index e7ead446c7..0007f78ae3 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -16,6 +16,7 @@ #include "networkd-manager.h" #include "networkd-network.h" #include "parse-util.h" +#include "path-lookup.h" #include "set.h" #include "socket-util.h" #include "stat-util.h" diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 9c82759818..71946c9ecc 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -20,6 +20,7 @@ #include "netlink-util.h" #include "network-internal.h" #include "parse-util.h" +#include "path-lookup.h" #include "path-util.h" #include "proc-cmdline.h" #include "random-util.h" From f1bb691a5aaf9ab67236c5a801381a022a00dde9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 24 Mar 2020 17:12:45 +0100 Subject: [PATCH 15/18] sd-path: export "systemd-network-path" Inspired by https://lists.freedesktop.org/archives/systemd-devel/2020-March/044169.html. --- man/sd_path_lookup.xml | 2 ++ src/basic/path-lookup.h | 1 + src/libsystemd/sd-path/sd-path.c | 7 ++++++- src/path/path.c | 2 ++ src/systemd/sd-path.h | 3 +++ 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/man/sd_path_lookup.xml b/man/sd_path_lookup.xml index 81812bc003..35a1109af3 100644 --- a/man/sd_path_lookup.xml +++ b/man/sd_path_lookup.xml @@ -98,6 +98,8 @@ SD_PATH_BINFMT_DIR, SD_PATH_MODULES_LOAD_DIR, SD_PATH_CATALOG_DIR, + + SD_PATH_SYSTEMD_NETWORK_PATH, }; diff --git a/src/basic/path-lookup.h b/src/basic/path-lookup.h index f67b8d416a..ae37f9feb9 100644 --- a/src/basic/path-lookup.h +++ b/src/basic/path-lookup.h @@ -71,3 +71,4 @@ char **generator_binary_paths(UnitFileScope scope); char **env_generator_binary_paths(bool is_system); #define NETWORK_DIRS ((const char* const*) CONF_PATHS_STRV("systemd/network")) +#define NETWORK_DIRS_NULSTR CONF_PATHS_NULSTR("systemd/network") diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c index 4fd96fb5a2..2a9c04a84d 100644 --- a/src/libsystemd/sd-path/sd-path.c +++ b/src/libsystemd/sd-path/sd-path.c @@ -633,7 +633,12 @@ static int get_search(uint64_t type, char ***list) { *list = t; return 0; - }} + } + + case SD_PATH_SYSTEMD_NETWORK_PATH: + return strv_from_nulstr(list, NETWORK_DIRS_NULSTR); + + } return -EOPNOTSUPP; } diff --git a/src/path/path.c b/src/path/path.c index aefdae1d51..20892fe1f2 100644 --- a/src/path/path.c +++ b/src/path/path.c @@ -81,6 +81,8 @@ static const char* const path_table[_SD_PATH_MAX] = { [SD_PATH_BINFMT_DIR] = "binfmt-dir", [SD_PATH_MODULES_LOAD_DIR] = "modules-load-dir", [SD_PATH_CATALOG_DIR] = "catalog-dir", + + [SD_PATH_SYSTEMD_NETWORK_PATH] = "systemd-network-path", }; static int list_homes(void) { diff --git a/src/systemd/sd-path.h b/src/systemd/sd-path.h index 203f01dd90..7da7a9f814 100644 --- a/src/systemd/sd-path.h +++ b/src/systemd/sd-path.h @@ -102,6 +102,9 @@ enum { SD_PATH_MODULES_LOAD_DIR, SD_PATH_CATALOG_DIR, + /* systemd-networkd search paths */ + SD_PATH_SYSTEMD_NETWORK_PATH, + _SD_PATH_MAX, }; From f52b9131e59bd1e5761c57cf1a0b5a5cff529ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 26 Mar 2020 16:48:16 +0100 Subject: [PATCH 16/18] man: fix typo --- man/sysctl.d.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/sysctl.d.xml b/man/sysctl.d.xml index 4df71e21eb..2735cb10dd 100644 --- a/man/sysctl.d.xml +++ b/man/sysctl.d.xml @@ -32,7 +32,7 @@ key.middle/part/with/dots.foo = 123 -key.that.will.not.fail = value key.pattern.*.with.glob = whatever -key.pattern.excluded.with.glob -key.pattern.overriden.with.glob = custom +key.pattern.overridden.with.glob = custom From e3420558512f880c46d14d23154582e3f9b3862b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 26 Mar 2020 17:33:43 +0100 Subject: [PATCH 17/18] path: log at debug level when we can't query a variable --- src/path/path.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/path/path.c b/src/path/path.c index 20892fe1f2..5d6afb96f0 100644 --- a/src/path/path.c +++ b/src/path/path.c @@ -94,11 +94,11 @@ static int list_homes(void) { int q; q = sd_path_lookup(i, arg_suffix, &p); - if (q == -ENXIO) - continue; if (q < 0) { - log_error_errno(r, "Failed to query %s: %m", path_table[i]); - r = q; + log_full_errno(q == -ENXIO ? LOG_DEBUG : LOG_ERR, + q, "Failed to query %s: %m", path_table[i]); + if (q != -ENXIO) + r = q; continue; } From 2e09fa89068fb191010e8f927dd20463c31d7bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 26 Mar 2020 17:40:33 +0100 Subject: [PATCH 18/18] sd-path: handle case of missing runtime dir in test Also document it in the man page. --- man/sd_path_lookup.xml | 8 ++++++++ src/test/test-sd-path.c | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/man/sd_path_lookup.xml b/man/sd_path_lookup.xml index 35a1109af3..68c6812ab1 100644 --- a/man/sd_path_lookup.xml +++ b/man/sd_path_lookup.xml @@ -172,6 +172,14 @@ Output argument is NULL. + + -ENXIO + + Query failed because of an undefined environment variable (e.g. for + SD_PATH_USER_RUNTIME when $XDG_RUNTIME_DIR is not + defined). + + -ENOMEM diff --git a/src/test/test-sd-path.c b/src/test/test-sd-path.c index 5888d3b9f9..9260db5ace 100644 --- a/src/test/test-sd-path.c +++ b/src/test/test-sd-path.c @@ -11,9 +11,13 @@ static void test_sd_path_lookup(void) { log_info("/* %s */", __func__); for (uint64_t i = 0; i < _SD_PATH_MAX; i++) { - _cleanup_free_ char *t, *s; + _cleanup_free_ char *t = NULL, *s = NULL; + int r; - assert_se(sd_path_lookup(i, NULL, &t) == 0); + r = sd_path_lookup(i, NULL, &t); + if (i == SD_PATH_USER_RUNTIME && r == -ENXIO) + continue; + assert_se(r == 0); assert_se(t); log_info("%02"PRIu64": \"%s\"", i, t); @@ -31,10 +35,14 @@ static void test_sd_path_lookup_strv(void) { log_info("/* %s */", __func__); for (uint64_t i = 0; i < _SD_PATH_MAX; i++) { - _cleanup_strv_free_ char **t, **s; + _cleanup_strv_free_ char **t = NULL, **s = NULL; char **item; + int r; - assert_se(sd_path_lookup_strv(i, NULL, &t) == 0); + r = sd_path_lookup_strv(i, NULL, &t); + if (i == SD_PATH_USER_RUNTIME && r == -ENXIO) + continue; + assert_se(r == 0); assert_se(t); log_info("%02"PRIu64":", i); STRV_FOREACH(item, t)