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.
This commit is contained in:
parent
205dd21ecc
commit
a7527131bb
|
@ -62,17 +62,18 @@ static int user_config_home(char **ret) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int user_runtime_dir(char **ret) {
|
static int user_runtime_dir(char **ret, const char *suffix) {
|
||||||
const char *e;
|
const char *e;
|
||||||
char *j;
|
char *j;
|
||||||
|
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
assert(suffix);
|
||||||
|
|
||||||
e = getenv("XDG_RUNTIME_DIR");
|
e = getenv("XDG_RUNTIME_DIR");
|
||||||
if (!e)
|
if (!e)
|
||||||
return -ENXIO;
|
return -ENXIO;
|
||||||
|
|
||||||
j = strappend(e, "/systemd/user");
|
j = strappend(e, suffix);
|
||||||
if (!j)
|
if (!j)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
@ -85,6 +86,7 @@ static int user_data_home_dir(char **ret, const char *suffix) {
|
||||||
char *j;
|
char *j;
|
||||||
|
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
assert(suffix);
|
||||||
|
|
||||||
/* We don't treat /etc/xdg/systemd here as the spec
|
/* We don't treat /etc/xdg/systemd here as the spec
|
||||||
* suggests because we assume that that is a link to
|
* 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) {
|
static int acquire_transient_dir(UnitFileScope scope, char **ret) {
|
||||||
char *transient;
|
|
||||||
|
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
switch (scope) {
|
switch (scope) {
|
||||||
|
|
||||||
case UNIT_FILE_SYSTEM:
|
case UNIT_FILE_SYSTEM: {
|
||||||
|
char *transient;
|
||||||
|
|
||||||
transient = strdup("/run/systemd/transient");
|
transient = strdup("/run/systemd/transient");
|
||||||
break;
|
if (!transient)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
case UNIT_FILE_USER: {
|
*ret = transient;
|
||||||
const char *e;
|
return 0;
|
||||||
|
|
||||||
e = getenv("XDG_RUNTIME_DIR");
|
|
||||||
if (!e)
|
|
||||||
return -ENXIO;
|
|
||||||
|
|
||||||
transient = strjoin(e, "/systemd/transient", NULL);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case UNIT_FILE_USER:
|
||||||
|
return user_runtime_dir(ret, "/systemd/transient");
|
||||||
|
|
||||||
case UNIT_FILE_GLOBAL:
|
case UNIT_FILE_GLOBAL:
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
|
@ -329,11 +328,6 @@ static int acquire_transient_dir(UnitFileScope scope, char **ret) {
|
||||||
assert_not_reached("Hmm, unexpected scope value.");
|
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) {
|
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)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = user_runtime_dir(runtime);
|
r = user_runtime_dir(runtime, "/systemd/user");
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue