diff options
author | Mike Yuan <me@yhndnzj.com> | 2024-09-14 19:14:33 +0200 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2024-10-06 19:42:39 +0200 |
commit | 0aae1a09a3868420c654c0f1e51927af81a7e3e5 (patch) | |
tree | e365c12473deda123b8372cc5670ccb076cf31f5 /src | |
parent | path-lookup: refactor lookup_paths_init() search paths handling (diff) | |
download | systemd-0aae1a09a3868420c654c0f1e51927af81a7e3e5.tar.xz systemd-0aae1a09a3868420c654c0f1e51927af81a7e3e5.zip |
path-lookup: move xdg_user_dirs() to xdg-autostart-generator
This is the only place where xdg_user_dir() is needed and
makes sense. All other invocations have been replaced with
user_search_dirs() - see previous commits for details.
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd/sd-path/path-lookup.c | 35 | ||||
-rw-r--r-- | src/libsystemd/sd-path/path-lookup.h | 2 | ||||
-rw-r--r-- | src/xdg-autostart-generator/xdg-autostart-generator.c | 35 |
3 files changed, 34 insertions, 38 deletions
diff --git a/src/libsystemd/sd-path/path-lookup.c b/src/libsystemd/sd-path/path-lookup.c index d56144f3cc..a3b09208cb 100644 --- a/src/libsystemd/sd-path/path-lookup.c +++ b/src/libsystemd/sd-path/path-lookup.c @@ -83,41 +83,6 @@ static const char* const user_config_unit_paths[] = { NULL }; -int xdg_user_dirs(char ***ret_config_dirs, char ***ret_data_dirs) { - /* Implement the mechanisms defined in - * - * https://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html - * - * We look in both the config and the data dirs because we - * want to encourage that distributors ship their unit files - * as data, and allow overriding as configuration. - */ - const char *e; - _cleanup_strv_free_ char **config_dirs = NULL, **data_dirs = NULL; - - e = getenv("XDG_CONFIG_DIRS"); - if (e) - config_dirs = strv_split(e, ":"); - else - config_dirs = strv_new("/etc/xdg"); - if (!config_dirs) - return -ENOMEM; - - e = getenv("XDG_DATA_DIRS"); - if (e) - data_dirs = strv_split(e, ":"); - else - data_dirs = strv_new("/usr/local/share", - "/usr/share"); - if (!data_dirs) - return -ENOMEM; - - *ret_config_dirs = TAKE_PTR(config_dirs); - *ret_data_dirs = TAKE_PTR(data_dirs); - - return 0; -} - bool path_is_user_data_dir(const char *path) { assert(path); diff --git a/src/libsystemd/sd-path/path-lookup.h b/src/libsystemd/sd-path/path-lookup.h index 3ef831323a..819c4cdb15 100644 --- a/src/libsystemd/sd-path/path-lookup.h +++ b/src/libsystemd/sd-path/path-lookup.h @@ -60,8 +60,6 @@ void lookup_paths_done(LookupPaths *p); int runtime_directory(RuntimeScope scope, const char *suffix, char **ret); -int xdg_user_dirs(char ***ret_config_dirs, char ***ret_data_dirs); - /* We don't treat /etc/xdg/systemd/ in these functions as the xdg base dir spec suggests because we assume * that is a link to /etc/systemd/ anyway. */ diff --git a/src/xdg-autostart-generator/xdg-autostart-generator.c b/src/xdg-autostart-generator/xdg-autostart-generator.c index 455f371fa8..47252c2e36 100644 --- a/src/xdg-autostart-generator/xdg-autostart-generator.c +++ b/src/xdg-autostart-generator/xdg-autostart-generator.c @@ -20,6 +20,39 @@ DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(xdgautostartservice_hash_ops, char, string_hash_func, string_compare_func, XdgAutostartService, xdg_autostart_service_free); +static int xdg_base_dirs(char ***ret_config_dirs, char ***ret_data_dirs) { + _cleanup_strv_free_ char **config_dirs = NULL, **data_dirs = NULL; + const char *e; + + /* Implement the mechanisms defined in + * https://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html */ + + assert(ret_config_dirs); + assert(ret_data_dirs); + + e = getenv("XDG_CONFIG_DIRS"); + if (e) + config_dirs = strv_split(e, ":"); + else + config_dirs = strv_new("/etc/xdg"); + if (!config_dirs) + return -ENOMEM; + + e = getenv("XDG_DATA_DIRS"); + if (e) + data_dirs = strv_split(e, ":"); + else + data_dirs = strv_new("/usr/local/share", + "/usr/share"); + if (!data_dirs) + return -ENOMEM; + + *ret_config_dirs = TAKE_PTR(config_dirs); + *ret_data_dirs = TAKE_PTR(data_dirs); + + return 0; +} + static int enumerate_xdg_autostart(Hashmap *all_services) { _cleanup_strv_free_ char **autostart_dirs = NULL; _cleanup_strv_free_ char **config_dirs = NULL; @@ -34,7 +67,7 @@ static int enumerate_xdg_autostart(Hashmap *all_services) { if (r < 0) return r; - r = xdg_user_dirs(&config_dirs, &data_dirs); + r = xdg_base_dirs(&config_dirs, &data_dirs); if (r < 0) return r; r = strv_extend_strv_concat(&autostart_dirs, (const char* const*) config_dirs, "/autostart"); |