summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/install.c24
-rw-r--r--src/shared/path-lookup.c163
-rw-r--r--src/shared/path-lookup.h13
3 files changed, 104 insertions, 96 deletions
diff --git a/src/shared/install.c b/src/shared/install.c
index 2cec6ba76f..f802343399 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -1442,7 +1442,7 @@ int unit_file_mask(
if (r < 0)
return r;
- r = lookup_paths_init_from_scope(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, root_dir);
if (r < 0)
return r;
@@ -1493,7 +1493,7 @@ int unit_file_unmask(
if (r < 0)
return r;
- r = lookup_paths_init_from_scope(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, root_dir);
if (r < 0)
return r;
@@ -1575,7 +1575,7 @@ int unit_file_link(
if (r < 0)
return r;
- r = lookup_paths_init_from_scope(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, root_dir);
if (r < 0)
return r;
@@ -1668,7 +1668,7 @@ int unit_file_add_dependency(
if (r < 0)
return r;
- r = lookup_paths_init_from_scope(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, root_dir);
if (r < 0)
return r;
@@ -1738,7 +1738,7 @@ int unit_file_enable(
if (r < 0)
return r;
- r = lookup_paths_init_from_scope(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, root_dir);
if (r < 0)
return r;
@@ -1786,7 +1786,7 @@ int unit_file_disable(
if (r < 0)
return r;
- r = lookup_paths_init_from_scope(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, root_dir);
if (r < 0)
return r;
@@ -1863,7 +1863,7 @@ int unit_file_set_default(
if (r < 0)
return r;
- r = lookup_paths_init_from_scope(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, root_dir);
if (r < 0)
return r;
@@ -1899,7 +1899,7 @@ int unit_file_get_default(
if (r < 0)
return r;
- r = lookup_paths_init_from_scope(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, root_dir);
if (r < 0)
return r;
@@ -2001,7 +2001,7 @@ int unit_file_get_state(
if (r < 0)
return r;
- r = lookup_paths_init_from_scope(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, root_dir);
if (r < 0)
return r;
@@ -2203,7 +2203,7 @@ int unit_file_preset(
if (r < 0)
return r;
- r = lookup_paths_init_from_scope(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, root_dir);
if (r < 0)
return r;
@@ -2244,7 +2244,7 @@ int unit_file_preset_all(
if (r < 0)
return r;
- r = lookup_paths_init_from_scope(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, root_dir);
if (r < 0)
return r;
@@ -2322,7 +2322,7 @@ int unit_file_get_list(
if (r < 0)
return r;
- r = lookup_paths_init_from_scope(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, root_dir);
if (r < 0)
return r;
diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c
index 5766053cef..cfe62c6438 100644
--- a/src/shared/path-lookup.c
+++ b/src/shared/path-lookup.c
@@ -102,7 +102,7 @@ static int user_data_home_dir(char **dir, const char *suffix) {
return -ENOMEM;
*dir = res;
- return 0;
+ return 1;
}
static char** user_dirs(
@@ -223,23 +223,32 @@ static char** user_dirs(
return tmp;
}
-char **generator_paths(ManagerRunningAs running_as) {
- if (running_as == MANAGER_USER)
- return strv_new("/run/systemd/user-generators",
- "/etc/systemd/user-generators",
- "/usr/local/lib/systemd/user-generators",
- USER_GENERATOR_PATH,
- NULL);
- else
+char **generator_paths(UnitFileScope scope) {
+
+ switch (scope) {
+
+ case UNIT_FILE_SYSTEM:
return strv_new("/run/systemd/system-generators",
"/etc/systemd/system-generators",
"/usr/local/lib/systemd/system-generators",
SYSTEM_GENERATOR_PATH,
NULL);
+
+ case UNIT_FILE_GLOBAL:
+ case UNIT_FILE_USER:
+ return strv_new("/run/systemd/user-generators",
+ "/etc/systemd/user-generators",
+ "/usr/local/lib/systemd/user-generators",
+ USER_GENERATOR_PATH,
+ NULL);
+
+ default:
+ assert_not_reached("Hmm, unexpected scope.");
+ }
}
static int acquire_generator_dirs(
- ManagerRunningAs running_as,
+ UnitFileScope scope,
char **generator,
char **generator_early,
char **generator_late) {
@@ -251,18 +260,28 @@ static int acquire_generator_dirs(
assert(generator_early);
assert(generator_late);
- if (running_as == MANAGER_SYSTEM)
+ switch (scope) {
+
+ case UNIT_FILE_SYSTEM:
prefix = "/run/systemd/";
- else {
- const char *e;
+ break;
- assert(running_as == MANAGER_USER);
+ case UNIT_FILE_USER: {
+ const char *e;
e = getenv("XDG_RUNTIME_DIR");
if (!e)
- return -EINVAL;
+ return -ENXIO;
prefix = strjoina(e, "/systemd/", NULL);
+ break;
+ }
+
+ case UNIT_FILE_GLOBAL:
+ return -EOPNOTSUPP;
+
+ default:
+ assert_not_reached("Hmm, unexpected scope value.");
}
x = strappend(prefix, "generator");
@@ -285,19 +304,26 @@ static int acquire_generator_dirs(
return 0;
}
-static int acquire_config_dirs(ManagerRunningAs running_as, bool personal, char **persistent, char **runtime) {
+static int acquire_config_dirs(UnitFileScope scope, char **persistent, char **runtime) {
_cleanup_free_ char *a = NULL, *b = NULL;
int r;
assert(persistent);
assert(runtime);
- if (running_as == MANAGER_SYSTEM) {
+ switch (scope) {
+
+ case UNIT_FILE_SYSTEM:
a = strdup(SYSTEM_CONFIG_UNIT_PATH);
b = strdup("/run/systemd/system");
- } else if (personal) {
- assert(running_as == MANAGER_USER);
+ break;
+
+ case UNIT_FILE_GLOBAL:
+ a = strdup(USER_CONFIG_UNIT_PATH);
+ b = strdup("/run/systemd/user");
+ break;
+ case UNIT_FILE_USER:
r = user_config_home(&a);
if (r < 0)
return r;
@@ -310,11 +336,9 @@ static int acquire_config_dirs(ManagerRunningAs running_as, bool personal, char
a = NULL;
return 0;
- } else {
- assert(running_as == MANAGER_USER);
- a = strdup(USER_CONFIG_UNIT_PATH);
- b = strdup("/run/systemd/user");
+ default:
+ assert_not_reached("Hmm, unexpected scope value.");
}
if (!a || !b)
@@ -350,8 +374,7 @@ static int patch_root_prefix(char **p, const char *root_dir) {
int lookup_paths_init(
LookupPaths *p,
- ManagerRunningAs running_as,
- bool personal,
+ UnitFileScope scope,
const char *root_dir) {
_cleanup_free_ char *generator = NULL, *generator_early = NULL, *generator_late = NULL,
@@ -362,15 +385,15 @@ int lookup_paths_init(
int r;
assert(p);
- assert(running_as >= 0);
- assert(running_as < _MANAGER_RUNNING_AS_MAX);
+ assert(scope >= 0);
+ assert(scope < _UNIT_FILE_SCOPE_MAX);
- r = acquire_config_dirs(running_as, personal, &persistent_config, &runtime_config);
+ r = acquire_config_dirs(scope, &persistent_config, &runtime_config);
if (r < 0)
return r;
- r = acquire_generator_dirs(running_as, &generator, &generator_early, &generator_late);
- if (r < 0)
+ r = acquire_generator_dirs(scope, &generator, &generator_early, &generator_late);
+ if (r < 0 && r != -EOPNOTSUPP && r != -ENXIO)
return r;
/* First priority is whatever has been passed to us via env
@@ -405,46 +428,56 @@ int lookup_paths_init(
* we include /lib in the search path for the system
* stuff but avoid it for user stuff. */
- if (running_as == MANAGER_USER) {
- if (personal)
- add = user_dirs(persistent_config, runtime_config,
- generator, generator_early, generator_late);
- else
- add = strv_new(
+ switch (scope) {
+
+ case UNIT_FILE_SYSTEM:
+ add = strv_new(
+ /* If you modify this you also want to modify
+ * systemdsystemunitpath= in systemd.pc.in! */
+ STRV_IFNOTNULL(generator_early),
+ persistent_config,
+ "/etc/systemd/system",
+ runtime_config,
+ "/run/systemd/system",
+ STRV_IFNOTNULL(generator),
+ "/usr/local/lib/systemd/system",
+ SYSTEM_DATA_UNIT_PATH,
+ "/usr/lib/systemd/system",
+#ifdef HAVE_SPLIT_USR
+ "/lib/systemd/system",
+#endif
+ STRV_IFNOTNULL(generator_late),
+ NULL);
+ break;
+
+ case UNIT_FILE_GLOBAL:
+ add = strv_new(
/* If you modify this you also want to modify
* systemduserunitpath= in systemd.pc.in, and
* the arrays in user_dirs() above! */
- generator_early,
+ STRV_IFNOTNULL(generator_early),
persistent_config,
"/etc/systemd/user",
runtime_config,
"/run/systemd/user",
- generator,
+ STRV_IFNOTNULL(generator),
"/usr/local/lib/systemd/user",
"/usr/local/share/systemd/user",
USER_DATA_UNIT_PATH,
"/usr/lib/systemd/user",
"/usr/share/systemd/user",
- generator_late,
+ STRV_IFNOTNULL(generator_late),
NULL);
- } else
- add = strv_new(
- /* If you modify this you also want to modify
- * systemdsystemunitpath= in systemd.pc.in! */
- generator_early,
- persistent_config,
- "/etc/systemd/system",
- runtime_config,
- "/run/systemd/system",
- generator,
- "/usr/local/lib/systemd/system",
- SYSTEM_DATA_UNIT_PATH,
- "/usr/lib/systemd/system",
-#ifdef HAVE_SPLIT_USR
- "/lib/systemd/system",
-#endif
- generator_late,
- NULL);
+ break;
+
+ case UNIT_FILE_USER:
+ add = user_dirs(persistent_config, runtime_config,
+ generator, generator_early, generator_late);
+ break;
+
+ default:
+ assert_not_reached("Hmm, unexpected scope?");
+ }
if (!add)
return -ENOMEM;
@@ -520,19 +553,3 @@ void lookup_paths_free(LookupPaths *p) {
p->generator_early = mfree(p->generator_early);
p->generator_late = mfree(p->generator_late);
}
-
-int lookup_paths_init_from_scope(
- LookupPaths *p,
- UnitFileScope scope,
- const char *root_dir) {
-
- assert(p);
- assert(scope >= 0);
- assert(scope < _UNIT_FILE_SCOPE_MAX);
-
- return lookup_paths_init(
- p,
- scope == UNIT_FILE_SYSTEM ? MANAGER_SYSTEM : MANAGER_USER,
- scope == UNIT_FILE_USER,
- root_dir);
-}
diff --git a/src/shared/path-lookup.h b/src/shared/path-lookup.h
index 64c8035c2b..974db79509 100644
--- a/src/shared/path-lookup.h
+++ b/src/shared/path-lookup.h
@@ -22,7 +22,6 @@
#include <stdbool.h>
typedef struct LookupPaths LookupPaths;
-typedef enum ManagerRunningAs ManagerRunningAs;
#include "install.h"
#include "macro.h"
@@ -40,20 +39,12 @@ struct LookupPaths {
char *generator_late;
};
-enum ManagerRunningAs {
- MANAGER_SYSTEM,
- MANAGER_USER,
- _MANAGER_RUNNING_AS_MAX,
- _MANAGER_RUNNING_AS_INVALID = -1
-};
-
int user_config_home(char **config_home);
int user_runtime_dir(char **runtime_dir);
-char **generator_paths(ManagerRunningAs running_as);
+char **generator_paths(UnitFileScope scope);
-int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal, const char *root_dir);
-int lookup_paths_init_from_scope(LookupPaths *p, UnitFileScope scope, const char *root_dir);
+int lookup_paths_init(LookupPaths *p, UnitFileScope scope, const char *root_dir);
void lookup_paths_free(LookupPaths *p);
#define _cleanup_lookup_paths_free_ _cleanup_(lookup_paths_free)