[systemd-devel] [PATCH 6/7] Better paths for transient user/session units
Hristo Venev
hristo at venev.name
Sun Dec 1 11:25:57 PST 2013
---
src/core/unit.c | 14 ++++++++++----
src/shared/path-lookup.c | 34 ++++++++++++++++++++++++++++++++++
src/shared/path-lookup.h | 2 ++
3 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/src/core/unit.c b/src/core/unit.c
index c963870..029f7ee 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2727,7 +2727,10 @@ static int drop_in_file(Unit *u, UnitSetPropertiesMode mode, const char *name, c
if (u->manager->running_as == SYSTEMD_USER) {
_cleanup_free_ char *c = NULL;
- r = user_config_home(&c);
+ if (mode & UNIT_PERSISTENT)
+ r = user_config_home(&c);
+ else
+ r = user_path_transient(&c);
if (r < 0)
return r;
if (r == 0)
@@ -2737,7 +2740,10 @@ static int drop_in_file(Unit *u, UnitSetPropertiesMode mode, const char *name, c
} else if (u->manager->running_as == SYSTEMD_SESSION) {
_cleanup_free_ char *c = NULL;
- r = session_config_home(&c);
+ if (mode & UNIT_PERSISTENT)
+ r = session_config_home(&c);
+ else
+ r = session_path_transient(&c);
if (r < 0)
return r;
if (r == 0)
@@ -2882,7 +2888,7 @@ int unit_make_transient(Unit *u) {
if (u->manager->running_as == SYSTEMD_USER) {
_cleanup_free_ char *c = NULL;
- r = user_config_home(&c);
+ r = user_path_transient(&c);
if (r < 0)
return r;
if (r == 0)
@@ -2896,7 +2902,7 @@ int unit_make_transient(Unit *u) {
} else if (u->manager->running_as == SYSTEMD_SESSION) {
_cleanup_free_ char *c = NULL;
- r = session_config_home(&c);
+ r = session_path_transient(&c);
if (r < 0)
return r;
if (r == 0)
diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c
index 58b1315..e7c9c7d 100644
--- a/src/shared/path-lookup.c
+++ b/src/shared/path-lookup.c
@@ -69,6 +69,23 @@ int user_config_home(char **config_home) {
return 0;
}
+int user_path_transient(char **path) {
+ const char *e;
+ char *r;
+
+ e = getenv("XDG_RUNTIME_DIR");
+ if (!e) {
+ return 0;
+ }
+ r = strappend(e, "/systemd/user");
+ if (!r)
+ return -ENOMEM;
+
+ *path = r;
+
+ return 1;
+}
+
int session_config_home(char **config_home) {
const char *e;
char *r;
@@ -98,6 +115,23 @@ int session_config_home(char **config_home) {
return 0;
}
+int session_path_transient(char **path) {
+ const char *e;
+ char *r;
+
+ e = getenv("XDG_SESSION_DIR");
+ if (!e) {
+ return 0;
+ }
+ r = strappend(e, "/systemd/session");
+ if (!r)
+ return -ENOMEM;
+
+ *path = r;
+
+ return 1;
+}
+
static char** user_dirs(
const char *generator,
const char *generator_early,
diff --git a/src/shared/path-lookup.h b/src/shared/path-lookup.h
index b1341aa..3d95fe2 100644
--- a/src/shared/path-lookup.h
+++ b/src/shared/path-lookup.h
@@ -43,7 +43,9 @@ const char* systemd_running_as_to_string(SystemdRunningAs i) _const_;
SystemdRunningAs systemd_running_as_from_string(const char *s) _pure_;
int user_config_home(char **config_home);
+int user_path_transient(char **path);
int session_config_home(char **config_home);
+int session_path_transient(char **path);
int lookup_paths_init(LookupPaths *p, SystemdRunningAs running_as, bool personal, const char *generator, const char *generator_early, const char *generator_late);
void lookup_paths_free(LookupPaths *p);
--
1.8.4.4
More information about the systemd-devel
mailing list