]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
path-lookup: move xdg_user_dirs() to xdg-autostart-generator 34432/head
authorMike Yuan <me@yhndnzj.com>
Sat, 14 Sep 2024 17:14:33 +0000 (19:14 +0200)
committerMike Yuan <me@yhndnzj.com>
Sun, 6 Oct 2024 17:42:39 +0000 (19:42 +0200)
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.

src/libsystemd/sd-path/path-lookup.c
src/libsystemd/sd-path/path-lookup.h
src/xdg-autostart-generator/xdg-autostart-generator.c

index d56144f3cc76d249ee73d6d7bef49409ec83309b..a3b09208cb3f8a819270966677d8d600f8d235e8 100644 (file)
@@ -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);
 
index 3ef831323a737b7b2333f89ff0bc371a71fab466..819c4cdb15d9f1700c5a641b4d814ff512e7d91d 100644 (file)
@@ -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. */
 
index 455f371fa8da16c7ff11949a8be837e0c0f65ea5..47252c2e3600485f42fd484934d73be018faee71 100644 (file)
 
 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");