While at it, place ret param at last.
_cleanup_strv_free_ char **files = NULL, **dirs = NULL;
int r;
- r = xdg_user_config_dir(&base, "/systemd");
+ r = xdg_user_config_dir("/systemd", &base);
if (r < 0)
return r;
/* Create the runtime directory and place the inaccessible device nodes there, if we run in
* user mode. In system mode mount_setup() already did that. */
- r = xdg_user_runtime_dir(&p, "/systemd");
+ r = xdg_user_runtime_dir("/systemd", &p);
if (r < 0) {
*ret_error_message = "$XDG_RUNTIME_DIR is not set";
return log_struct_errno(LOG_EMERG, r,
r = mkdir_label("/run/systemd/units", 0755);
else {
_cleanup_free_ char *units_path = NULL;
- r = xdg_user_runtime_dir(&units_path, "/systemd/units");
+ r = xdg_user_runtime_dir("/systemd/units", &units_path);
if (r < 0)
return r;
p = strjoin("/run/systemd/units/invocation:", u->id);
else {
_cleanup_free_ char *user_path = NULL;
- r = xdg_user_runtime_dir(&user_path, "/systemd/units/invocation:");
+
+ r = xdg_user_runtime_dir("/systemd/units/invocation:", &user_path);
if (r < 0)
return r;
+
p = strjoin(user_path, u->id);
}
-
if (!p)
return -ENOMEM;
#include "tmpfile-util.h"
#include "user-util.h"
-int xdg_user_runtime_dir(char **ret, const char *suffix) {
- const char *e;
- char *j;
-
- assert(ret);
- assert(suffix);
-
- e = getenv("XDG_RUNTIME_DIR");
- if (!e)
- return -ENXIO;
-
- j = path_join(e, suffix);
- if (!j)
- return -ENOMEM;
-
- *ret = j;
- return 0;
-}
-
-int xdg_user_config_dir(char **ret, const char *suffix) {
- _cleanup_free_ char *j = NULL;
- const char *e;
- int r;
-
- assert(ret);
-
- e = getenv("XDG_CONFIG_HOME");
- if (e) {
- j = path_join(e, suffix);
- if (!j)
- return -ENOMEM;
- } else {
- r = get_home_dir(&j);
- if (r < 0)
- return r;
-
- if (!path_extend(&j, "/.config", suffix))
- return -ENOMEM;
- }
-
- *ret = TAKE_PTR(j);
- return 0;
-}
-
-int xdg_user_data_dir(char **ret, const char *suffix) {
- _cleanup_free_ char *j = NULL;
- const char *e;
- int r;
-
- assert(ret);
- assert(suffix);
-
- /* We don't treat /etc/xdg/systemd here as the spec
- * suggests because we assume that is a link to
- * /etc/systemd/ anyway. */
-
- e = getenv("XDG_DATA_HOME");
- if (e) {
- j = path_join(e, suffix);
- if (!j)
- return -ENOMEM;
- } else {
- r = get_home_dir(&j);
- if (r < 0)
- return r;
-
- if (!path_extend(&j, "/.local/share", suffix))
- return -ENOMEM;
- }
-
- *ret = TAKE_PTR(j);
- return 1;
-}
-
int runtime_directory(char **ret, RuntimeScope scope, const char *suffix) {
int r;
return strdup_to(ret, e);
if (scope == RUNTIME_SCOPE_USER) {
- r = xdg_user_runtime_dir(ret, suffix);
+ r = xdg_user_runtime_dir(suffix, ret);
if (r < 0)
return r;
} else {
if (r < 0)
return NULL;
- r = xdg_user_data_dir(&data_home, "/systemd/user");
+ r = xdg_user_data_dir("/systemd/user", &data_home);
if (r < 0 && r != -ENXIO)
return NULL;
else if (scope == RUNTIME_SCOPE_SYSTEM)
transient = strdup("/run/systemd/transient");
else
- return xdg_user_runtime_dir(ret, "/systemd/transient");
+ return xdg_user_runtime_dir("/systemd/transient", ret);
if (!transient)
return -ENOMEM;
break;
case RUNTIME_SCOPE_USER:
- r = xdg_user_config_dir(&a, "/systemd/user");
+ r = xdg_user_config_dir("/systemd/user", &a);
if (r < 0 && r != -ENXIO)
return r;
- r = xdg_user_runtime_dir(runtime, "/systemd/user");
+ r = xdg_user_runtime_dir("/systemd/user", runtime);
if (r < 0) {
if (r != -ENXIO)
return r;
}
case RUNTIME_SCOPE_USER:
- r = xdg_user_config_dir(&a, "/systemd/user.control");
+ r = xdg_user_config_dir("/systemd/user.control", &a);
if (r < 0 && r != -ENXIO)
return r;
- r = xdg_user_runtime_dir(runtime, "/systemd/user.control");
+ r = xdg_user_runtime_dir("/systemd/user.control", runtime);
if (r < 0) {
if (r != -ENXIO)
return r;
#include <stdbool.h>
+#include "sd-path.h"
+
#include "runtime-scope.h"
typedef enum LookupPathsFlags {
int lookup_paths_init(LookupPaths *lp, RuntimeScope scope, LookupPathsFlags flags, const char *root_dir);
int lookup_paths_init_or_warn(LookupPaths *lp, RuntimeScope scope, LookupPathsFlags flags, const char *root_dir);
+void lookup_paths_log(LookupPaths *p);
+void lookup_paths_done(LookupPaths *p);
+
int xdg_user_dirs(char ***ret_config_dirs, char ***ret_data_dirs);
-int xdg_user_runtime_dir(char **ret, const char *suffix);
-int xdg_user_config_dir(char **ret, const char *suffix);
-int xdg_user_data_dir(char **ret, const char *suffix);
+
+/* 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. */
+
+static inline int xdg_user_runtime_dir(const char *suffix, char **ret) {
+ return sd_path_lookup(SD_PATH_USER_RUNTIME, suffix, ret);
+}
+static inline int xdg_user_config_dir(const char *suffix, char **ret) {
+ return sd_path_lookup(SD_PATH_USER_CONFIGURATION, suffix, ret);
+}
+static inline int xdg_user_data_dir(const char *suffix, char **ret) {
+ return sd_path_lookup(SD_PATH_USER_SHARED, suffix, ret);
+}
int runtime_directory(char **ret, RuntimeScope scope, const char *suffix);
bool path_is_user_data_dir(const char *path);
bool path_is_user_config_dir(const char *path);
-void lookup_paths_log(LookupPaths *p);
-void lookup_paths_done(LookupPaths *p);
-
char **generator_binary_paths(RuntimeScope scope);
char **env_generator_binary_paths(RuntimeScope scope);
if (r < 0)
return r;
- r = xdg_user_config_dir(&persistent_config, "/user-tmpfiles.d");
+ r = xdg_user_config_dir("/user-tmpfiles.d", &persistent_config);
if (r < 0 && !ERRNO_IS_NEG_NOINFO(r))
return r;
- r = xdg_user_runtime_dir(&runtime_config, "/user-tmpfiles.d");
+ r = xdg_user_runtime_dir("/user-tmpfiles.d", &runtime_config);
if (r < 0 && !ERRNO_IS_NEG_NOINFO(r))
return r;
- r = xdg_user_data_dir(&data_home, "/user-tmpfiles.d");
+ r = xdg_user_data_dir("/user-tmpfiles.d", &data_home);
if (r < 0 && !ERRNO_IS_NEG_NOINFO(r))
return r;
* Prioritising entries in "more specific" directories */
_cleanup_free_ char *user_firmware_dir = NULL;
- r = xdg_user_config_dir(&user_firmware_dir, "/qemu/firmware");
+ r = xdg_user_config_dir("/qemu/firmware", &user_firmware_dir);
if (r < 0)
return r;
_cleanup_free_ char *user_config_autostart_dir = NULL;
int r;
- r = xdg_user_config_dir(&user_config_autostart_dir, "/autostart");
+ r = xdg_user_config_dir("/autostart", &user_config_autostart_dir);
if (r < 0)
return r;
r = strv_extend(&autostart_dirs, user_config_autostart_dir);