summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-02-29 20:56:47 +0100
committerLennart Poettering <lennart@poettering.net>2016-04-12 13:43:31 +0200
commita7527131bbae88b44469a44f9d97325d70762981 (patch)
treeef4b85761b89699ed9364195c06522ab2e6c0ff0
parent205dd21eccf6332fdb57f2d2ad9df70ab2c30cb1 (diff)
path-lookup: make user_runtime_dir() more generic
Let's make the suffix it appends configurable. This way we can reuse it at a second place.
-rw-r--r--src/shared/path-lookup.c36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c
index 17a9ca2aac..0735e3b4f5 100644
--- a/src/shared/path-lookup.c
+++ b/src/shared/path-lookup.c
@@ -62,17 +62,18 @@ static int user_config_home(char **ret) {
return 0;
}
-static int user_runtime_dir(char **ret) {
+static int 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 = strappend(e, "/systemd/user");
+ j = strappend(e, suffix);
if (!j)
return -ENOMEM;
@@ -85,6 +86,7 @@ static int user_data_home_dir(char **ret, const char *suffix) {
char *j;
assert(ret);
+ assert(suffix);
/* We don't treat /etc/xdg/systemd here as the spec
* suggests because we assume that that is a link to
@@ -301,27 +303,24 @@ static int acquire_generator_dirs(
}
static int acquire_transient_dir(UnitFileScope scope, char **ret) {
- char *transient;
-
assert(ret);
switch (scope) {
- case UNIT_FILE_SYSTEM:
- transient = strdup("/run/systemd/transient");
- break;
-
- case UNIT_FILE_USER: {
- const char *e;
+ case UNIT_FILE_SYSTEM: {
+ char *transient;
- e = getenv("XDG_RUNTIME_DIR");
- if (!e)
- return -ENXIO;
+ transient = strdup("/run/systemd/transient");
+ if (!transient)
+ return -ENOMEM;
- transient = strjoin(e, "/systemd/transient", NULL);
- break;
+ *ret = transient;
+ return 0;
}
+ case UNIT_FILE_USER:
+ return user_runtime_dir(ret, "/systemd/transient");
+
case UNIT_FILE_GLOBAL:
return -EOPNOTSUPP;
@@ -329,11 +328,6 @@ static int acquire_transient_dir(UnitFileScope scope, char **ret) {
assert_not_reached("Hmm, unexpected scope value.");
}
- if (!transient)
- return -ENOMEM;
-
- *ret = transient;
- return 0;
}
static int acquire_config_dirs(UnitFileScope scope, char **persistent, char **runtime) {
@@ -360,7 +354,7 @@ static int acquire_config_dirs(UnitFileScope scope, char **persistent, char **ru
if (r < 0)
return r;
- r = user_runtime_dir(runtime);
+ r = user_runtime_dir(runtime, "/systemd/user");
if (r < 0)
return r;