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/xdg-autostart-generator | |
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/xdg-autostart-generator')
-rw-r--r-- | src/xdg-autostart-generator/xdg-autostart-generator.c | 35 |
1 files changed, 34 insertions, 1 deletions
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"); |