return 0;
}
-int runtime_directory(RuntimeScope scope, const char *suffix, char **ret) {
+int runtime_directory_generic(RuntimeScope scope, const char *suffix, char **ret) {
int r;
- assert(IN_SET(scope, RUNTIME_SCOPE_SYSTEM, RUNTIME_SCOPE_USER));
- assert(suffix);
assert(ret);
- /* Accept $RUNTIME_DIRECTORY as authoritative
- * If it's missing, apply the suffix to /run/, or $XDG_RUNTIME_DIR if we are in a user runtime scope.
- *
- * Return value indicates whether the suffix was applied or not */
+ /* This does not bother with $RUNTIME_DIRECTORY, and hence can be applied to get other service's
+ * runtime dir */
- const char *e = secure_getenv("RUNTIME_DIRECTORY");
- if (e)
- return strdup_to(ret, e);
-
- if (scope == RUNTIME_SCOPE_USER) {
+ switch (scope) {
+ case RUNTIME_SCOPE_USER:
r = xdg_user_runtime_dir(suffix, ret);
if (r < 0)
return r;
- } else {
+ break;
+
+ case RUNTIME_SCOPE_SYSTEM: {
char *d = path_join("/run", suffix);
if (!d)
return -ENOMEM;
*ret = d;
+ break;
+ }
+
+ default:
+ return -EINVAL;
}
+ return 0;
+}
+
+int runtime_directory(RuntimeScope scope, const char *fallback_suffix, char **ret) {
+ int r;
+
+ assert(ret);
+
+ /* Accept $RUNTIME_DIRECTORY as authoritative, i.e. only works for our service's own runtime dir.
+ *
+ * If it's missing, apply the suffix to /run/, or $XDG_RUNTIME_DIR if we are in a user runtime scope.
+ *
+ * Return value indicates whether the suffix was applied or not. */
+
+ const char *e = secure_getenv("RUNTIME_DIRECTORY");
+ if (e)
+ return strdup_to(ret, e);
+
+ r = runtime_directory_generic(scope, fallback_suffix, ret);
+ if (r < 0)
+ return r;
+
return 1;
}
void lookup_paths_log(LookupPaths *p);
void lookup_paths_done(LookupPaths *p);
-int runtime_directory(RuntimeScope scope, const char *suffix, char **ret);
+int runtime_directory_generic(RuntimeScope scope, const char *suffix, char **ret);
+int runtime_directory(RuntimeScope scope, const char *fallback_suffix, char **ret);
/* 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. */