]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: remove ManagerRunningAs enum
authorLennart Poettering <lennart@poettering.net>
Wed, 24 Feb 2016 20:24:23 +0000 (21:24 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Apr 2016 11:43:30 +0000 (13:43 +0200)
Previously, we had two enums ManagerRunningAs and UnitFileScope, that were
mostly identical and converted from one to the other all the time. The latter
had one more value UNIT_FILE_GLOBAL however.

Let's simplify things, and remove ManagerRunningAs and replace it by
UnitFileScope everywhere, thus making the translation unnecessary. Introduce
two new macros MANAGER_IS_SYSTEM() and MANAGER_IS_USER() to simplify checking
if we are running in one or the user context.

36 files changed:
src/analyze/analyze-verify.c
src/analyze/analyze-verify.h
src/analyze/analyze.c
src/core/automount.c
src/core/busname.c
src/core/cgroup.c
src/core/dbus-manager.c
src/core/dbus.c
src/core/device.c
src/core/failure-action.c
src/core/job.c
src/core/load-fragment.c
src/core/main.c
src/core/manager.c
src/core/manager.h
src/core/mount.c
src/core/path.c
src/core/service.c
src/core/socket.c
src/core/swap.c
src/core/timer.c
src/core/unit-printf.c
src/core/unit.c
src/shared/install.c
src/shared/path-lookup.c
src/shared/path-lookup.h
src/systemctl/systemctl.c
src/sysv-generator/sysv-generator.c
src/test/test-cgroup-mask.c
src/test/test-engine.c
src/test/test-execute.c
src/test/test-path-lookup.c
src/test/test-path.c
src/test/test-sched-prio.c
src/test/test-unit-file.c
src/test/test-unit-name.c

index b83f559e7db931d92970223d1e8b656d785beef6..5fd3ee49eb30228d7ad149af9652accad96ce76d 100644 (file)
@@ -231,14 +231,12 @@ static int verify_unit(Unit *u, bool check_man) {
         return r;
 }
 
-int verify_units(char **filenames, ManagerRunningAs running_as, bool check_man) {
+int verify_units(char **filenames, UnitFileScope scope, bool check_man) {
         _cleanup_(sd_bus_error_free) sd_bus_error err = SD_BUS_ERROR_NULL;
+        _cleanup_free_ char *var = NULL;
         Manager *m = NULL;
         FILE *serial = NULL;
         FDSet *fdset = NULL;
-
-        _cleanup_free_ char *var = NULL;
-
         char **filename;
         int r = 0, k;
 
@@ -255,7 +253,7 @@ int verify_units(char **filenames, ManagerRunningAs running_as, bool check_man)
 
         assert_se(set_unit_path(var) >= 0);
 
-        r = manager_new(running_as, true, &m);
+        r = manager_new(scope, true, &m);
         if (r < 0)
                 return log_error_errno(r, "Failed to initialize manager: %m");
 
index 27c253a56280439d4f2a3c9937d258832d3faece..d8204dc69c01421c7c209e2f4ac71a9f2bb5de16 100644 (file)
@@ -23,4 +23,4 @@
 
 #include "path-lookup.h"
 
-int verify_units(char **filenames, ManagerRunningAs running_as, bool check_man);
+int verify_units(char **filenames, UnitFileScope scope, bool check_man);
index 42754a27415e589cfd8c7fc874d3b528bf7216d2..5e03c0c5e036d963d0a201870c4c9d0defc38bf7 100644 (file)
@@ -1443,7 +1443,7 @@ int main(int argc, char *argv[]) {
 
         if (streq_ptr(argv[optind], "verify"))
                 r = verify_units(argv+optind+1,
-                                 arg_user ? MANAGER_USER : MANAGER_SYSTEM,
+                                 arg_user ? UNIT_FILE_USER : UNIT_FILE_SYSTEM,
                                  arg_man);
         else {
                 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
index 5dc6fd98e7e3ad396ce9158fef4d519090b28255..7c55d7bc49d9064eda035e546dd93466b0b6ddd5 100644 (file)
@@ -149,7 +149,7 @@ static int automount_add_default_dependencies(Automount *a) {
         if (!UNIT(a)->default_dependencies)
                 return 0;
 
-        if (UNIT(a)->manager->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(UNIT(a)->manager))
                 return 0;
 
         r = unit_add_two_dependencies_by_name(UNIT(a), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, NULL, true);
index de2a21ccdec56bf0b36159bcade684059c635f6c..bbe61af4f024968b5cc1e405f948f308cabc74b3 100644 (file)
@@ -149,7 +149,7 @@ static int busname_add_default_default_dependencies(BusName *n) {
         if (r < 0)
                 return r;
 
-        if (UNIT(n)->manager->running_as == MANAGER_SYSTEM) {
+        if (MANAGER_IS_SYSTEM(UNIT(n)->manager)) {
                 r = unit_add_two_dependencies_by_name(UNIT(n), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, NULL, true);
                 if (r < 0)
                         return r;
@@ -318,7 +318,7 @@ static int busname_open_fd(BusName *n) {
         if (n->starter_fd >= 0)
                 return 0;
 
-        mode = UNIT(n)->manager->running_as == MANAGER_SYSTEM ? "system" : "user";
+        mode = MANAGER_IS_SYSTEM(UNIT(n)->manager) ? "system" : "user";
         n->starter_fd = bus_kernel_open_bus_fd(mode, &path);
         if (n->starter_fd < 0)
                 return log_unit_warning_errno(UNIT(n), n->starter_fd, "Failed to open %s: %m", path ?: "kdbus");
index 9c34928052bcc0f4f61c3b9c3ad23797c1f6f5a4..25cc6962f9be52451cc1ca59309ea46e1978e114 100644 (file)
@@ -1265,7 +1265,7 @@ int manager_setup_cgroup(Manager *m) {
          * it. This is to support live upgrades from older systemd
          * versions where PID 1 was moved there. Also see
          * cg_get_root_path(). */
-        if (!e && m->running_as == MANAGER_SYSTEM) {
+        if (!e && MANAGER_IS_SYSTEM(m)) {
                 e = endswith(m->cgroup_root, "/" SPECIAL_SYSTEM_SLICE);
                 if (!e)
                         e = endswith(m->cgroup_root, "/system"); /* even more legacy */
@@ -1318,7 +1318,7 @@ int manager_setup_cgroup(Manager *m) {
 
                         (void) sd_event_source_set_description(m->cgroup_inotify_event_source, "cgroup-inotify");
 
-                } else if (m->running_as == MANAGER_SYSTEM) {
+                } else if (MANAGER_IS_SYSTEM(m)) {
 
                         /* On the legacy hierarchy we only get
                          * notifications via cgroup agents. (Which
index e187e19d03b6f1afdefb634f0ce86d18daaeb936..5fc3526751fd5de661709198ab9db277aeaf1861 100644 (file)
@@ -1187,7 +1187,7 @@ static int method_reboot(sd_bus_message *message, void *userdata, sd_bus_error *
         if (r < 0)
                 return r;
 
-        if (m->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(m))
                 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers.");
 
         m->exit_code = MANAGER_REBOOT;
@@ -1206,7 +1206,7 @@ static int method_poweroff(sd_bus_message *message, void *userdata, sd_bus_error
         if (r < 0)
                 return r;
 
-        if (m->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(m))
                 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers.");
 
         m->exit_code = MANAGER_POWEROFF;
@@ -1225,7 +1225,7 @@ static int method_halt(sd_bus_message *message, void *userdata, sd_bus_error *er
         if (r < 0)
                 return r;
 
-        if (m->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(m))
                 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Halt is only supported for system managers.");
 
         m->exit_code = MANAGER_HALT;
@@ -1244,7 +1244,7 @@ static int method_kexec(sd_bus_message *message, void *userdata, sd_bus_error *e
         if (r < 0)
                 return r;
 
-        if (m->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(m))
                 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "KExec is only supported for system managers.");
 
         m->exit_code = MANAGER_KEXEC;
@@ -1265,7 +1265,7 @@ static int method_switch_root(sd_bus_message *message, void *userdata, sd_bus_er
         if (r < 0)
                 return r;
 
-        if (m->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(m))
                 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Root switching is only supported by system manager.");
 
         r = sd_bus_message_read(message, "ss", &root, &init);
@@ -1433,7 +1433,7 @@ static int method_set_exit_code(sd_bus_message *message, void *userdata, sd_bus_
         if (r < 0)
                 return r;
 
-        if (m->running_as == MANAGER_SYSTEM && detect_container() <= 0)
+        if (MANAGER_IS_SYSTEM(m) && detect_container() <= 0)
                 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "ExitCode can only be set for user service managers or in containers.");
 
         m->return_value = code;
@@ -1466,7 +1466,7 @@ static int method_list_unit_files(sd_bus_message *message, void *userdata, sd_bu
         if (!h)
                 return -ENOMEM;
 
-        r = unit_file_get_list(m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, h);
+        r = unit_file_get_list(m->unit_file_scope, NULL, h);
         if (r < 0)
                 goto fail;
 
@@ -1498,7 +1498,6 @@ static int method_get_unit_file_state(sd_bus_message *message, void *userdata, s
         Manager *m = userdata;
         const char *name;
         UnitFileState state;
-        UnitFileScope scope;
         int r;
 
         assert(message);
@@ -1514,9 +1513,7 @@ static int method_get_unit_file_state(sd_bus_message *message, void *userdata, s
         if (r < 0)
                 return r;
 
-        scope = m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
-
-        r = unit_file_get_state(scope, NULL, name, &state);
+        r = unit_file_get_state(m->unit_file_scope, NULL, name, &state);
         if (r < 0)
                 return r;
 
@@ -1526,7 +1523,6 @@ static int method_get_unit_file_state(sd_bus_message *message, void *userdata, s
 static int method_get_default_target(sd_bus_message *message, void *userdata, sd_bus_error *error) {
         _cleanup_free_ char *default_target = NULL;
         Manager *m = userdata;
-        UnitFileScope scope;
         int r;
 
         assert(message);
@@ -1538,9 +1534,7 @@ static int method_get_default_target(sd_bus_message *message, void *userdata, sd
         if (r < 0)
                 return r;
 
-        scope = m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
-
-        r = unit_file_get_default(scope, NULL, &default_target);
+        r = unit_file_get_default(m->unit_file_scope, NULL, &default_target);
         if (r < 0)
                 return r;
 
@@ -1624,7 +1618,6 @@ static int method_enable_unit_files_generic(
         _cleanup_strv_free_ char **l = NULL;
         UnitFileChange *changes = NULL;
         unsigned n_changes = 0;
-        UnitFileScope scope;
         int runtime, force, r;
 
         assert(message);
@@ -1644,9 +1637,7 @@ static int method_enable_unit_files_generic(
         if (r == 0)
                 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
 
-        scope = m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
-
-        r = call(scope, runtime, NULL, l, force, &changes, &n_changes);
+        r = call(m->unit_file_scope, runtime, NULL, l, force, &changes, &n_changes);
         if (r == -ESHUTDOWN)
                 return sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, "Unit file is masked.");
         if (r == -EADDRNOTAVAIL)
@@ -1688,7 +1679,6 @@ static int method_preset_unit_files_with_mode(sd_bus_message *message, void *use
         unsigned n_changes = 0;
         Manager *m = userdata;
         UnitFilePresetMode mm;
-        UnitFileScope scope;
         int runtime, force, r;
         const char *mode;
 
@@ -1717,9 +1707,7 @@ static int method_preset_unit_files_with_mode(sd_bus_message *message, void *use
         if (r == 0)
                 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
 
-        scope = m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
-
-        r = unit_file_preset(scope, runtime, NULL, l, mm, force, &changes, &n_changes);
+        r = unit_file_preset(m->unit_file_scope, runtime, NULL, l, mm, force, &changes, &n_changes);
         if (r < 0)
                 return r;
 
@@ -1736,7 +1724,6 @@ static int method_disable_unit_files_generic(
         _cleanup_strv_free_ char **l = NULL;
         UnitFileChange *changes = NULL;
         unsigned n_changes = 0;
-        UnitFileScope scope;
         int r, runtime;
 
         assert(message);
@@ -1750,15 +1737,13 @@ static int method_disable_unit_files_generic(
         if (r < 0)
                 return r;
 
-        scope = m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
-
         r = bus_verify_manage_unit_files_async(m, message, error);
         if (r < 0)
                 return r;
         if (r == 0)
                 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
 
-        r = call(scope, runtime, NULL, l, &changes, &n_changes);
+        r = call(m->unit_file_scope, runtime, NULL, l, &changes, &n_changes);
         if (r < 0)
                 return r;
 
@@ -1777,7 +1762,6 @@ static int method_set_default_target(sd_bus_message *message, void *userdata, sd
         UnitFileChange *changes = NULL;
         unsigned n_changes = 0;
         Manager *m = userdata;
-        UnitFileScope scope;
         const char *name;
         int force, r;
 
@@ -1798,9 +1782,7 @@ static int method_set_default_target(sd_bus_message *message, void *userdata, sd
         if (r == 0)
                 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
 
-        scope = m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
-
-        r = unit_file_set_default(scope, NULL, name, force, &changes, &n_changes);
+        r = unit_file_set_default(m->unit_file_scope, NULL, name, force, &changes, &n_changes);
         if (r < 0)
                 return r;
 
@@ -1812,7 +1794,6 @@ static int method_preset_all_unit_files(sd_bus_message *message, void *userdata,
         unsigned n_changes = 0;
         Manager *m = userdata;
         UnitFilePresetMode mm;
-        UnitFileScope scope;
         const char *mode;
         int force, runtime, r;
 
@@ -1841,9 +1822,7 @@ static int method_preset_all_unit_files(sd_bus_message *message, void *userdata,
         if (r == 0)
                 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
 
-        scope = m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
-
-        r = unit_file_preset_all(scope, runtime, NULL, mm, force, &changes, &n_changes);
+        r = unit_file_preset_all(m->unit_file_scope, runtime, NULL, mm, force, &changes, &n_changes);
         if (r < 0) {
                 unit_file_changes_free(changes, n_changes);
                 return r;
@@ -1857,7 +1836,6 @@ static int method_add_dependency_unit_files(sd_bus_message *message, void *userd
         Manager *m = userdata;
         UnitFileChange *changes = NULL;
         unsigned n_changes = 0;
-        UnitFileScope scope;
         int runtime, force, r;
         char *target;
         char *type;
@@ -1884,9 +1862,7 @@ static int method_add_dependency_unit_files(sd_bus_message *message, void *userd
         if (dep < 0)
                 return -EINVAL;
 
-        scope = m->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
-
-        r = unit_file_add_dependency(scope, runtime, NULL, l, target, dep, force, &changes, &n_changes);
+        r = unit_file_add_dependency(m->unit_file_scope, runtime, NULL, l, target, dep, force, &changes, &n_changes);
         if (r == -ESHUTDOWN)
                 return sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, "Unit file is masked.");
         if (r == -EADDRNOTAVAIL)
index 413489373fd5994cc44e9db21b039a4054c426b9..263955d874652065ce8832597461110a6e77995b 100644 (file)
@@ -112,7 +112,7 @@ static int signal_agent_released(sd_bus_message *message, void *userdata, sd_bus
         manager_notify_cgroup_empty(m, cgroup);
 
         /* if running as system-instance, forward under our name */
-        if (m->running_as == MANAGER_SYSTEM && m->system_bus) {
+        if (MANAGER_IS_SYSTEM(m) && m->system_bus) {
                 r = sd_bus_message_rewind(message, 1);
                 if (r >= 0)
                         r = sd_bus_send(m->system_bus, message, NULL);
@@ -690,7 +690,7 @@ static int bus_on_connection(sd_event_source *s, int fd, uint32_t revents, void
                 return 0;
         }
 
-        if (m->running_as == MANAGER_SYSTEM) {
+        if (MANAGER_IS_SYSTEM(m)) {
                 /* When we run as system instance we get the Released
                  * signal via a direct connection */
 
@@ -864,10 +864,10 @@ static int bus_init_api(Manager *m) {
                 return 0;
 
         /* The API and system bus is the same if we are running in system mode */
-        if (m->running_as == MANAGER_SYSTEM && m->system_bus)
+        if (MANAGER_IS_SYSTEM(m) && m->system_bus)
                 bus = sd_bus_ref(m->system_bus);
         else {
-                if (m->running_as == MANAGER_SYSTEM)
+                if (MANAGER_IS_SYSTEM(m))
                         r = sd_bus_open_system(&bus);
                 else
                         r = sd_bus_open_user(&bus);
@@ -907,7 +907,7 @@ static int bus_setup_system(Manager *m, sd_bus *bus) {
         assert(bus);
 
         /* On kdbus or if we are a user instance we get the Released message via the system bus */
-        if (m->running_as == MANAGER_USER || m->kdbus_fd >= 0) {
+        if (MANAGER_IS_USER(m) || m->kdbus_fd >= 0) {
                 r = sd_bus_add_match(
                                 bus,
                                 NULL,
@@ -932,7 +932,7 @@ static int bus_init_system(Manager *m) {
                 return 0;
 
         /* The API and system bus is the same if we are running in system mode */
-        if (m->running_as == MANAGER_SYSTEM && m->api_bus) {
+        if (MANAGER_IS_SYSTEM(m) && m->api_bus) {
                 m->system_bus = sd_bus_ref(m->api_bus);
                 return 0;
         }
@@ -983,7 +983,7 @@ static int bus_init_private(Manager *m) {
         if (m->kdbus_fd >= 0)
                 return 0;
 
-        if (m->running_as == MANAGER_SYSTEM) {
+        if (MANAGER_IS_SYSTEM(m)) {
 
                 /* We want the private bus only when running as init */
                 if (getpid() != 1)
@@ -1082,7 +1082,7 @@ static void destroy_bus(Manager *m, sd_bus **bus) {
 
         /* Possibly flush unwritten data, but only if we are
          * unprivileged, since we don't want to sync here */
-        if (m->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(m))
                 sd_bus_flush(*bus);
 
         /* And destroy the object */
index 0671620a3ed18c37f3c4597f01a6e0a118bba361..d01bec53d8d362c60c898d608d822aa2395d9734 100644 (file)
@@ -265,7 +265,7 @@ static int device_add_udev_wants(Unit *u, struct udev_device *dev) {
         assert(u);
         assert(dev);
 
-        property = u->manager->running_as == MANAGER_USER ? "SYSTEMD_USER_WANTS" : "SYSTEMD_WANTS";
+        property = MANAGER_IS_USER(u->manager) ? "SYSTEMD_USER_WANTS" : "SYSTEMD_WANTS";
         wants = udev_device_get_property_value(dev, property);
         if (!wants)
                 return 0;
index bb2bc3f399fc5c4cc0db4f9f03c995fa7398e51f..d4aae4b6e793d4b1e5ff3d53bce6cc46155f226c 100644 (file)
@@ -47,7 +47,7 @@ int failure_action(
         if (action == FAILURE_ACTION_NONE)
                 return -ECANCELED;
 
-        if (m->running_as == MANAGER_USER) {
+        if (!MANAGER_IS_SYSTEM(m)) {
                 /* Downgrade all options to simply exiting if we run
                  * in user mode */
 
index 5557a6a9423d65e3cdd86422d4a9a47982abc961..2e30431163e2c3d5d428fd2dd4cd88ddab32d9d8 100644 (file)
@@ -1156,7 +1156,7 @@ void job_shutdown_magic(Job *j) {
         if (j->type != JOB_START)
                 return;
 
-        if (j->unit->manager->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(j->unit->manager))
                 return;
 
         if (!unit_has_name(j->unit, SPECIAL_SHUTDOWN_TARGET))
index 3a77ceb5518338c32b72087b9d25453cfa1e20ea..79f13f135d220a1e6443d56eae919bfd61b77561 100644 (file)
@@ -2495,7 +2495,7 @@ int config_parse_syscall_filter(
 
         /* Turn on NNP, but only if it wasn't configured explicitly
          * before, and only if we are in user mode. */
-        if (!c->no_new_privileges_set && u->manager->running_as == MANAGER_USER)
+        if (!c->no_new_privileges_set && MANAGER_IS_USER(u->manager))
                 c->no_new_privileges = true;
 
         return 0;
index 56df32426a9c121d07575af1ffbb9364fc5bb753..a428e345e087baf58a19209fc379e72422546d07 100644 (file)
@@ -94,7 +94,7 @@ static enum {
         ACTION_DONE
 } arg_action = ACTION_RUN;
 static char *arg_default_unit = NULL;
-static ManagerRunningAs arg_running_as = _MANAGER_RUNNING_AS_INVALID;
+static bool arg_system = false;
 static bool arg_dump_core = true;
 static int arg_crash_chvt = -1;
 static bool arg_crash_shell = false;
@@ -688,11 +688,11 @@ static int parse_config_file(void) {
 
         const char *fn, *conf_dirs_nulstr;
 
-        fn = arg_running_as == MANAGER_SYSTEM ?
+        fn = arg_system ?
                 PKGSYSCONFDIR "/system.conf" :
                 PKGSYSCONFDIR "/user.conf";
 
-        conf_dirs_nulstr = arg_running_as == MANAGER_SYSTEM ?
+        conf_dirs_nulstr = arg_system ?
                 CONF_PATHS_NULSTR("systemd/system.conf.d") :
                 CONF_PATHS_NULSTR("systemd/user.conf.d");
 
@@ -866,11 +866,11 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case ARG_SYSTEM:
-                        arg_running_as = MANAGER_SYSTEM;
+                        arg_system = true;
                         break;
 
                 case ARG_USER:
-                        arg_running_as = MANAGER_USER;
+                        arg_system = false;
                         break;
 
                 case ARG_TEST:
@@ -1346,7 +1346,7 @@ int main(int argc, char *argv[]) {
         if (getpid() == 1 && detect_container() <= 0) {
 
                 /* Running outside of a container as PID 1 */
-                arg_running_as = MANAGER_SYSTEM;
+                arg_system = true;
                 make_null_stdio();
                 log_set_target(LOG_TARGET_KMSG);
                 log_open();
@@ -1430,7 +1430,7 @@ int main(int argc, char *argv[]) {
 
         } else if (getpid() == 1) {
                 /* Running inside a container, as PID 1 */
-                arg_running_as = MANAGER_SYSTEM;
+                arg_system = true;
                 log_set_target(LOG_TARGET_CONSOLE);
                 log_close_console(); /* force reopen of /dev/console */
                 log_open();
@@ -1443,7 +1443,7 @@ int main(int argc, char *argv[]) {
                 kernel_timestamp = DUAL_TIMESTAMP_NULL;
         } else {
                 /* Running as user instance */
-                arg_running_as = MANAGER_USER;
+                arg_system = false;
                 log_set_target(LOG_TARGET_AUTO);
                 log_open();
 
@@ -1501,7 +1501,7 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
-        if (arg_running_as == MANAGER_SYSTEM) {
+        if (arg_system) {
                 r = parse_proc_cmdline(parse_proc_cmdline_item);
                 if (r < 0)
                         log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
@@ -1522,14 +1522,14 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
-        if (arg_running_as == MANAGER_USER &&
+        if (!arg_system &&
             arg_action == ACTION_RUN &&
             sd_booted() <= 0) {
                 log_error("Trying to run as user instance, but the system has not been booted with systemd.");
                 goto finish;
         }
 
-        if (arg_running_as == MANAGER_SYSTEM &&
+        if (arg_system &&
             arg_action == ACTION_RUN &&
             running_in_chroot() > 0) {
                 log_error("Cannot be run in a chroot() environment.");
@@ -1557,7 +1557,7 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
-        if (arg_running_as == MANAGER_USER &&
+        if (!arg_system &&
             !getenv("XDG_RUNTIME_DIR")) {
                 log_error("Trying to run as user instance, but $XDG_RUNTIME_DIR is not set.");
                 goto finish;
@@ -1580,7 +1580,7 @@ int main(int argc, char *argv[]) {
         if (arg_serialization)
                 assert_se(fdset_remove(fds, fileno(arg_serialization)) >= 0);
 
-        if (arg_running_as == MANAGER_SYSTEM)
+        if (arg_system)
                 /* Become a session leader if we aren't one yet. */
                 setsid();
 
@@ -1589,7 +1589,7 @@ int main(int argc, char *argv[]) {
 
         /* Reset the console, but only if this is really init and we
          * are freshly booted */
-        if (arg_running_as == MANAGER_SYSTEM && arg_action == ACTION_RUN) {
+        if (arg_system && arg_action == ACTION_RUN) {
 
                 /* If we are init, we connect stdin/stdout/stderr to
                  * /dev/null and make sure we don't have a controlling
@@ -1616,7 +1616,7 @@ int main(int argc, char *argv[]) {
                         goto finish;
         }
 
-        if (arg_running_as == MANAGER_SYSTEM) {
+        if (arg_system) {
                 int v;
 
                 log_info(PACKAGE_STRING " running in %ssystem mode. (" SYSTEMD_FEATURES ")",
@@ -1652,7 +1652,7 @@ int main(int argc, char *argv[]) {
                           arg_action == ACTION_TEST ? " test" : "", getuid(), t);
         }
 
-        if (arg_running_as == MANAGER_SYSTEM && !skip_setup) {
+        if (arg_system && !skip_setup) {
                 if (arg_show_status > 0)
                         status_welcome();
 
@@ -1664,7 +1664,7 @@ int main(int argc, char *argv[]) {
                 test_usr();
         }
 
-        if (arg_running_as == MANAGER_SYSTEM && arg_runtime_watchdog > 0 && arg_runtime_watchdog != USEC_INFINITY)
+        if (arg_system && arg_runtime_watchdog > 0 && arg_runtime_watchdog != USEC_INFINITY)
                 watchdog_set_timeout(&arg_runtime_watchdog);
 
         if (arg_timer_slack_nsec != NSEC_INFINITY)
@@ -1694,12 +1694,12 @@ int main(int argc, char *argv[]) {
                 }
         }
 
-        if (arg_running_as == MANAGER_USER)
+        if (!arg_system)
                 /* Become reaper of our children */
                 if (prctl(PR_SET_CHILD_SUBREAPER, 1) < 0)
                         log_warning_errno(errno, "Failed to make us a subreaper: %m");
 
-        if (arg_running_as == MANAGER_SYSTEM) {
+        if (arg_system) {
                 bump_rlimit_nofile(&saved_rlimit_nofile);
 
                 if (empty_etc) {
@@ -1711,7 +1711,7 @@ int main(int argc, char *argv[]) {
                 }
         }
 
-        r = manager_new(arg_running_as, arg_action == ACTION_TEST, &m);
+        r = manager_new(arg_system ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, arg_action == ACTION_TEST, &m);
         if (r < 0) {
                 log_emergency_errno(r, "Failed to allocate manager object: %m");
                 error_message = "Failed to allocate manager object";
@@ -1874,7 +1874,7 @@ int main(int argc, char *argv[]) {
                 case MANAGER_EXIT:
                         retval = m->return_value;
 
-                        if (m->running_as == MANAGER_USER) {
+                        if (MANAGER_IS_USER(m)) {
                                 log_debug("Exit.");
                                 goto finish;
                         }
@@ -1970,7 +1970,7 @@ finish:
                         args[i++] = SYSTEMD_BINARY_PATH;
                         if (switch_root_dir)
                                 args[i++] = "--switched-root";
-                        args[i++] = arg_running_as == MANAGER_SYSTEM ? "--system" : "--user";
+                        args[i++] = arg_system ? "--system" : "--user";
                         args[i++] = "--deserialize";
                         args[i++] = sfd;
                         args[i++] = NULL;
index 79dc77d50e07cd37cec7217a0ef897c47e897c5a..1412d6718a7377f87dbd5d1448f52dfc21ea0f80 100644 (file)
@@ -491,7 +491,7 @@ static int manager_setup_signals(Manager *m) {
         if (r < 0)
                 return r;
 
-        if (m->running_as == MANAGER_SYSTEM)
+        if (MANAGER_IS_SYSTEM(m))
                 return enable_special_signals(m);
 
         return 0;
@@ -518,7 +518,7 @@ static void manager_clean_environment(Manager *m) {
 static int manager_default_environment(Manager *m) {
         assert(m);
 
-        if (m->running_as == MANAGER_SYSTEM) {
+        if (MANAGER_IS_SYSTEM(m)) {
                 /* The system manager always starts with a clean
                  * environment for its children. It does not import
                  * the kernel or the parents exported variables.
@@ -547,43 +547,36 @@ static int manager_default_environment(Manager *m) {
 }
 
 
-int manager_new(ManagerRunningAs running_as, bool test_run, Manager **_m) {
-
-        static const char * const unit_log_fields[_MANAGER_RUNNING_AS_MAX] = {
-                [MANAGER_SYSTEM] = "UNIT=",
-                [MANAGER_USER] = "USER_UNIT=",
-        };
-
-        static const char * const unit_log_format_strings[_MANAGER_RUNNING_AS_MAX] = {
-                [MANAGER_SYSTEM] = "UNIT=%s",
-                [MANAGER_USER] = "USER_UNIT=%s",
-        };
-
+int manager_new(UnitFileScope scope, bool test_run, Manager **_m) {
         Manager *m;
         int r;
 
         assert(_m);
-        assert(running_as >= 0);
-        assert(running_as < _MANAGER_RUNNING_AS_MAX);
+        assert(IN_SET(scope, UNIT_FILE_SYSTEM, UNIT_FILE_USER));
 
         m = new0(Manager, 1);
         if (!m)
                 return -ENOMEM;
 
-#ifdef ENABLE_EFI
-        if (running_as == MANAGER_SYSTEM && detect_container() <= 0)
-                boot_timestamps(&m->userspace_timestamp, &m->firmware_timestamp, &m->loader_timestamp);
-#endif
-
-        m->running_as = running_as;
+        m->unit_file_scope = scope;
         m->exit_code = _MANAGER_EXIT_CODE_INVALID;
         m->default_timer_accuracy_usec = USEC_PER_MINUTE;
         m->default_tasks_accounting = true;
         m->default_tasks_max = UINT64_C(512);
 
+#ifdef ENABLE_EFI
+        if (MANAGER_IS_SYSTEM(m) && detect_container() <= 0)
+                boot_timestamps(&m->userspace_timestamp, &m->firmware_timestamp, &m->loader_timestamp);
+#endif
+
         /* Prepare log fields we can use for structured logging */
-        m->unit_log_field = unit_log_fields[running_as];
-        m->unit_log_format_string = unit_log_format_strings[running_as];
+        if (MANAGER_IS_SYSTEM(m)) {
+                m->unit_log_field = "UNIT=";
+                m->unit_log_format_string = "UNIT=%s";
+        } else {
+                m->unit_log_field = "USER_UNIT=";
+                m->unit_log_format_string = "USER_UNIT=%s";
+        }
 
         m->idle_pipe[0] = m->idle_pipe[1] = m->idle_pipe[2] = m->idle_pipe[3] = -1;
 
@@ -694,7 +687,7 @@ static int manager_setup_notify(Manager *m) {
 
                 fd_inc_rcvbuf(fd, NOTIFY_RCVBUF_SIZE);
 
-                if (m->running_as == MANAGER_SYSTEM)
+                if (MANAGER_IS_SYSTEM(m))
                         m->notify_socket = strdup("/run/systemd/notify");
                 else {
                         const char *e;
@@ -756,8 +749,8 @@ static int manager_setup_kdbus(Manager *m) {
                 return -ESOCKTNOSUPPORT;
 
         m->kdbus_fd = bus_kernel_create_bus(
-                        m->running_as == MANAGER_SYSTEM ? "system" : "user",
-                        m->running_as == MANAGER_SYSTEM, &p);
+                        MANAGER_IS_SYSTEM(m) ? "system" : "user",
+                        MANAGER_IS_SYSTEM(m), &p);
 
         if (m->kdbus_fd < 0)
                 return log_debug_errno(m->kdbus_fd, "Failed to set up kdbus: %m");
@@ -778,7 +771,7 @@ static int manager_connect_bus(Manager *m, bool reexecuting) {
         try_bus_connect =
                 m->kdbus_fd >= 0 ||
                 reexecuting ||
-                (m->running_as == MANAGER_USER && getenv("DBUS_SESSION_BUS_ADDRESS"));
+                (MANAGER_IS_USER(m) && getenv("DBUS_SESSION_BUS_ADDRESS"));
 
         /* Try to connect to the buses, if possible. */
         return bus_init(m, try_bus_connect);
@@ -1116,7 +1109,7 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
 
         assert(m);
 
-        r = lookup_paths_init(&m->lookup_paths, m->running_as, true, NULL);
+        r = lookup_paths_init(&m->lookup_paths, m->unit_file_scope, NULL);
         if (r < 0)
                 return r;
 
@@ -1739,7 +1732,7 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t
                 }
 
                 log_received_signal(sfsi.ssi_signo == SIGCHLD ||
-                                    (sfsi.ssi_signo == SIGTERM && m->running_as == MANAGER_USER)
+                                    (sfsi.ssi_signo == SIGTERM && MANAGER_IS_USER(m))
                                     ? LOG_DEBUG : LOG_INFO,
                                     &sfsi);
 
@@ -1750,7 +1743,7 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t
                         break;
 
                 case SIGTERM:
-                        if (m->running_as == MANAGER_SYSTEM) {
+                        if (MANAGER_IS_SYSTEM(m)) {
                                 /* This is for compatibility with the
                                  * original sysvinit */
                                 m->exit_code = MANAGER_REEXECUTE;
@@ -1760,7 +1753,7 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t
                         /* Fall through */
 
                 case SIGINT:
-                        if (m->running_as == MANAGER_SYSTEM) {
+                        if (MANAGER_IS_SYSTEM(m)) {
 
                                 /* If the user presses C-A-D more than
                                  * 7 times within 2s, we reboot
@@ -1786,14 +1779,14 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t
                         break;
 
                 case SIGWINCH:
-                        if (m->running_as == MANAGER_SYSTEM)
+                        if (MANAGER_IS_SYSTEM(m))
                                 manager_start_target(m, SPECIAL_KBREQUEST_TARGET, JOB_REPLACE);
 
                         /* This is a nop on non-init */
                         break;
 
                 case SIGPWR:
-                        if (m->running_as == MANAGER_SYSTEM)
+                        if (MANAGER_IS_SYSTEM(m))
                                 manager_start_target(m, SPECIAL_SIGPWR_TARGET, JOB_REPLACE);
 
                         /* This is a nop on non-init */
@@ -1901,7 +1894,7 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t
                                 break;
 
                         case 24:
-                                if (m->running_as == MANAGER_USER) {
+                                if (MANAGER_IS_USER(m)) {
                                         m->exit_code = MANAGER_EXIT;
                                         return 0;
                                 }
@@ -2017,7 +2010,7 @@ int manager_loop(Manager *m) {
         while (m->exit_code == MANAGER_OK) {
                 usec_t wait_usec;
 
-                if (m->runtime_watchdog > 0 && m->runtime_watchdog != USEC_INFINITY && m->running_as == MANAGER_SYSTEM)
+                if (m->runtime_watchdog > 0 && m->runtime_watchdog != USEC_INFINITY && MANAGER_IS_SYSTEM(m))
                         watchdog_ping();
 
                 if (!ratelimit_test(&rl)) {
@@ -2042,7 +2035,7 @@ int manager_loop(Manager *m) {
                         continue;
 
                 /* Sleep for half the watchdog time */
-                if (m->runtime_watchdog > 0 && m->runtime_watchdog != USEC_INFINITY && m->running_as == MANAGER_SYSTEM) {
+                if (m->runtime_watchdog > 0 && m->runtime_watchdog != USEC_INFINITY && MANAGER_IS_SYSTEM(m)) {
                         wait_usec = m->runtime_watchdog / 2;
                         if (wait_usec <= 0)
                                 wait_usec = 1;
@@ -2113,7 +2106,7 @@ void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success) {
         const char *msg;
         int audit_fd, r;
 
-        if (m->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(m))
                 return;
 
         audit_fd = get_audit_fd();
@@ -2159,7 +2152,7 @@ void manager_send_unit_plymouth(Manager *m, Unit *u) {
         if (m->n_reloading > 0)
                 return;
 
-        if (m->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(m))
                 return;
 
         if (detect_container() > 0)
@@ -2203,7 +2196,7 @@ int manager_open_serialization(Manager *m, FILE **_f) {
 
         assert(_f);
 
-        path = m->running_as == MANAGER_SYSTEM ? "/run/systemd" : "/tmp";
+        path = MANAGER_IS_SYSTEM(m) ? "/run/systemd" : "/tmp";
         fd = open_tmpfile(path, O_RDWR|O_CLOEXEC);
         if (fd < 0)
                 return -errno;
@@ -2537,7 +2530,7 @@ int manager_reload(Manager *m) {
         manager_undo_generators(m);
         lookup_paths_free(&m->lookup_paths);
 
-        q = lookup_paths_init(&m->lookup_paths, m->running_as, true, NULL);
+        q = lookup_paths_init(&m->lookup_paths, m->unit_file_scope, NULL);
         if (q < 0 && r >= 0)
                 r = q;
 
@@ -2616,7 +2609,7 @@ static void manager_notify_finished(Manager *m) {
         if (m->test_run)
                 return;
 
-        if (m->running_as == MANAGER_SYSTEM && detect_container() <= 0) {
+        if (MANAGER_IS_SYSTEM(m) && detect_container() <= 0) {
 
                 /* Note that m->kernel_usec.monotonic is always at 0,
                  * and m->firmware_usec.monotonic and
@@ -2733,7 +2726,7 @@ static int manager_run_generators(Manager *m) {
         if (m->test_run)
                 return 0;
 
-        paths = generator_paths(m->running_as);
+        paths = generator_paths(m->unit_file_scope);
         if (!paths)
                 return log_oom();
 
@@ -2851,7 +2844,7 @@ void manager_recheck_journal(Manager *m) {
 
         assert(m);
 
-        if (m->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(m))
                 return;
 
         u = manager_get_unit(m, SPECIAL_JOURNALD_SOCKET);
@@ -2875,7 +2868,7 @@ void manager_set_show_status(Manager *m, ShowStatus mode) {
         assert(m);
         assert(IN_SET(mode, SHOW_STATUS_AUTO, SHOW_STATUS_NO, SHOW_STATUS_YES, SHOW_STATUS_TEMPORARY));
 
-        if (m->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(m))
                 return;
 
         if (m->show_status != mode)
@@ -2892,7 +2885,7 @@ void manager_set_show_status(Manager *m, ShowStatus mode) {
 static bool manager_get_show_status(Manager *m, StatusType type) {
         assert(m);
 
-        if (m->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(m))
                 return false;
 
         if (m->no_console_output)
@@ -2914,7 +2907,7 @@ static bool manager_get_show_status(Manager *m, StatusType type) {
 void manager_set_first_boot(Manager *m, bool b) {
         assert(m);
 
-        if (m->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(m))
                 return;
 
         if (m->first_boot != (int) b) {
@@ -2960,7 +2953,7 @@ Set *manager_get_units_requiring_mounts_for(Manager *m, const char *path) {
 const char *manager_get_runtime_prefix(Manager *m) {
         assert(m);
 
-        return m->running_as == MANAGER_SYSTEM ?
+        return MANAGER_IS_SYSTEM(m) ?
                "/run" :
                getenv("XDG_RUNTIME_DIR");
 }
index 5471bd7a0d54afbc633d2e20c6b678312c0eba30..19eab958eaeb7c8a815247e895506ca7a1992e95 100644 (file)
@@ -140,6 +140,7 @@ struct Manager {
 
         sd_event_source *jobs_in_progress_event_source;
 
+        UnitFileScope unit_file_scope;
         LookupPaths lookup_paths;
         Set *unit_path_cache;
 
@@ -224,7 +225,6 @@ struct Manager {
         unsigned n_in_gc_queue;
 
         /* Flags */
-        ManagerRunningAs running_as;
         ManagerExitCode exit_code:5;
 
         bool dispatching_load_queue:1;
@@ -300,10 +300,13 @@ struct Manager {
         const char *unit_log_field;
         const char *unit_log_format_string;
 
-        int first_boot;
+        int first_boot; /* tri-state */
 };
 
-int manager_new(ManagerRunningAs running_as, bool test_run, Manager **m);
+#define MANAGER_IS_SYSTEM(m) ((m)->unit_file_scope == UNIT_FILE_SYSTEM)
+#define MANAGER_IS_USER(m) ((m)->unit_file_scope != UNIT_FILE_SYSTEM)
+
+int manager_new(UnitFileScope scope, bool test_run, Manager **m);
 Manager* manager_free(Manager *m);
 
 void manager_enumerate(Manager *m);
index 0fd880df5dae67f45c7dbe67acd352f46e56df9b..74ab54bfd01b3315b9cd2d7f23e2b00c78d6b5ff 100644 (file)
@@ -336,8 +336,7 @@ static int mount_add_device_links(Mount *m) {
         if (path_equal(m->where, "/"))
                 return 0;
 
-        if (mount_is_auto(p) && !mount_is_automount(p) &&
-            UNIT(m)->manager->running_as == MANAGER_SYSTEM)
+        if (mount_is_auto(p) && !mount_is_automount(p) && MANAGER_IS_SYSTEM(UNIT(m)->manager))
                 device_wants_mount = true;
 
         r = unit_add_node_link(UNIT(m), p->what, device_wants_mount, m->from_fragment ? UNIT_BINDS_TO : UNIT_REQUIRES);
@@ -353,7 +352,7 @@ static int mount_add_quota_links(Mount *m) {
 
         assert(m);
 
-        if (UNIT(m)->manager->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(UNIT(m)->manager))
                 return 0;
 
         p = get_mount_parameters_fragment(m);
@@ -400,7 +399,7 @@ static int mount_add_default_dependencies(Mount *m) {
         if (!UNIT(m)->default_dependencies)
                 return 0;
 
-        if (UNIT(m)->manager->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(UNIT(m)->manager))
                 return 0;
 
         /* We do not add any default dependencies to /, /usr or
@@ -1396,7 +1395,7 @@ static int mount_setup_unit(
                         goto fail;
                 }
 
-                if (m->running_as == MANAGER_SYSTEM) {
+                if (MANAGER_IS_SYSTEM(m)) {
                         const char* target;
 
                         target = mount_needs_network(options, fstype) ?  SPECIAL_REMOTE_FS_TARGET : SPECIAL_LOCAL_FS_TARGET;
@@ -1424,7 +1423,7 @@ static int mount_setup_unit(
                         }
                 }
 
-                if (m->running_as == MANAGER_SYSTEM &&
+                if (MANAGER_IS_SYSTEM(m) &&
                     mount_needs_network(options, fstype)) {
                         /* _netdev option may have shown up late, or on a
                          * remount. Add remote-fs dependencies, even though
index 426c4ad299dbf4394d95e8a65ec10b827ddf46f0..5e7b3eb2342f1990980a7bd1352ed9266197decc 100644 (file)
@@ -318,7 +318,7 @@ static int path_add_default_dependencies(Path *p) {
         if (r < 0)
                 return r;
 
-        if (UNIT(p)->manager->running_as == MANAGER_SYSTEM) {
+        if (MANAGER_IS_SYSTEM(UNIT(p)->manager)) {
                 r = unit_add_two_dependencies_by_name(UNIT(p), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, NULL, true);
                 if (r < 0)
                         return r;
index c5cbf0f1529297a7f22201682cef1b4ab93dc977..7aea6f7ff4106a56163d072e88f3e7865c24e74a 100644 (file)
@@ -523,7 +523,7 @@ static int service_add_default_dependencies(Service *s) {
         /* Add a number of automatic dependencies useful for the
          * majority of services. */
 
-        if (UNIT(s)->manager->running_as == MANAGER_SYSTEM) {
+        if (MANAGER_IS_SYSTEM(UNIT(s)->manager)) {
                 /* First, pull in the really early boot stuff, and
                  * require it, so that we fail if we can't acquire
                  * it. */
@@ -1211,7 +1211,7 @@ static int service_spawn(
                 if (asprintf(our_env + n_env++, "MAINPID="PID_FMT, s->main_pid) < 0)
                         return -ENOMEM;
 
-        if (UNIT(s)->manager->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(UNIT(s)->manager))
                 if (asprintf(our_env + n_env++, "MANAGERPID="PID_FMT, getpid()) < 0)
                         return -ENOMEM;
 
index dd515a17a57b7f475efdbd449a7c60302dc8abf6..65da0e3c5e97c794d415826c3eb49e8ea134a779 100644 (file)
@@ -301,7 +301,7 @@ static int socket_add_default_dependencies(Socket *s) {
         if (r < 0)
                 return r;
 
-        if (UNIT(s)->manager->running_as == MANAGER_SYSTEM) {
+        if (MANAGER_IS_SYSTEM(UNIT(s)->manager)) {
                 r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, NULL, true);
                 if (r < 0)
                         return r;
index 11506d9ecb092eaa4f949e7d2057f7b59143d7c0..c6502eb821123b450feffb7256bd264dd299bf5b 100644 (file)
@@ -198,7 +198,7 @@ static int swap_add_device_links(Swap *s) {
                 return 0;
 
         if (is_device_path(s->what))
-                return unit_add_node_link(UNIT(s), s->what, UNIT(s)->manager->running_as == MANAGER_SYSTEM, UNIT_BINDS_TO);
+                return unit_add_node_link(UNIT(s), s->what, MANAGER_IS_SYSTEM(UNIT(s)->manager), UNIT_BINDS_TO);
         else
                 /* File based swap devices need to be ordered after
                  * systemd-remount-fs.service, since they might need a
@@ -214,7 +214,7 @@ static int swap_add_default_dependencies(Swap *s) {
         if (!UNIT(s)->default_dependencies)
                 return 0;
 
-        if (UNIT(s)->manager->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(UNIT(s)->manager))
                 return 0;
 
         if (detect_container() > 0)
index 3d0bae16e5daeb4f21e951f0f9bf3099ddb7f057..a51a67ea11cb69d0155fc39599eed01618a9715c 100644 (file)
@@ -109,7 +109,7 @@ static int timer_add_default_dependencies(Timer *t) {
         if (r < 0)
                 return r;
 
-        if (UNIT(t)->manager->running_as == MANAGER_SYSTEM) {
+        if (MANAGER_IS_SYSTEM(UNIT(t)->manager)) {
                 r = unit_add_two_dependencies_by_name(UNIT(t), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, NULL, true);
                 if (r < 0)
                         return r;
@@ -135,7 +135,7 @@ static int timer_setup_persistent(Timer *t) {
         if (!t->persistent)
                 return 0;
 
-        if (UNIT(t)->manager->running_as == MANAGER_SYSTEM) {
+        if (MANAGER_IS_SYSTEM(UNIT(t)->manager)) {
 
                 r = unit_require_mounts_for(UNIT(t), "/var/lib/systemd/timers");
                 if (r < 0)
index fc057d965c636ce52d0cf49d895434c1c2607ef5..40da52fcac84de6128f7d1c70f9cd315ac021154 100644 (file)
@@ -140,7 +140,7 @@ static int specifier_runtime(char specifier, void *data, void *userdata, char **
 
         assert(u);
 
-        if (u->manager->running_as == MANAGER_SYSTEM)
+        if (MANAGER_IS_SYSTEM(u->manager))
                 e = "/run";
         else {
                 e = getenv("XDG_RUNTIME_DIR");
index 70175557f74db5aa1781a3d606aa1c38909b5211..fbc2b0d74d7f6f592735e02c7cdb397c6ac530db 100644 (file)
@@ -814,7 +814,7 @@ int unit_add_exec_dependencies(Unit *u, ExecContext *c) {
                         return r;
         }
 
-        if (u->manager->running_as != MANAGER_SYSTEM)
+        if (!MANAGER_IS_SYSTEM(u->manager))
                 return 0;
 
         if (c->private_tmp) {
@@ -2413,7 +2413,7 @@ int unit_set_default_slice(Unit *u) {
                 if (!escaped)
                         return -ENOMEM;
 
-                if (u->manager->running_as == MANAGER_SYSTEM)
+                if (MANAGER_IS_SYSTEM(u->manager))
                         b = strjoin("system-", escaped, ".slice", NULL);
                 else
                         b = strappend(escaped, ".slice");
@@ -2423,7 +2423,7 @@ int unit_set_default_slice(Unit *u) {
                 slice_name = b;
         } else
                 slice_name =
-                        u->manager->running_as == MANAGER_SYSTEM && !unit_has_name(u, SPECIAL_INIT_SCOPE)
+                        MANAGER_IS_SYSTEM(u->manager) && !unit_has_name(u, SPECIAL_INIT_SCOPE)
                         ? SPECIAL_SYSTEM_SLICE
                         : SPECIAL_ROOT_SLICE;
 
@@ -2884,7 +2884,7 @@ int unit_add_node_link(Unit *u, const char *what, bool wants, UnitDependency dep
                 return r;
 
         r = unit_add_two_dependencies(u, UNIT_AFTER,
-                                      u->manager->running_as == MANAGER_SYSTEM ? dep : UNIT_WANTS,
+                                      MANAGER_IS_SYSTEM(u->manager) ? dep : UNIT_WANTS,
                                       device, true);
         if (r < 0)
                 return r;
@@ -3158,7 +3158,7 @@ UnitFileState unit_get_unit_file_state(Unit *u) {
 
         if (u->unit_file_state < 0 && u->fragment_path) {
                 r = unit_file_get_state(
-                                u->manager->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER,
+                                u->manager->unit_file_scope,
                                 NULL,
                                 basename(u->fragment_path),
                                 &u->unit_file_state);
@@ -3174,7 +3174,7 @@ int unit_get_unit_file_preset(Unit *u) {
 
         if (u->unit_file_preset < 0 && u->fragment_path)
                 u->unit_file_preset = unit_file_query_preset(
-                                u->manager->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER,
+                                u->manager->unit_file_scope,
                                 NULL,
                                 basename(u->fragment_path));
 
@@ -3225,7 +3225,7 @@ int unit_patch_contexts(Unit *u) {
                                         return -ENOMEM;
                         }
 
-                if (u->manager->running_as == MANAGER_USER &&
+                if (MANAGER_IS_USER(u->manager) &&
                     !ec->working_directory) {
 
                         r = get_home_dir(&ec->working_directory);
@@ -3237,7 +3237,7 @@ int unit_patch_contexts(Unit *u) {
                         ec->working_directory_missing_ok = true;
                 }
 
-                if (u->manager->running_as == MANAGER_USER &&
+                if (MANAGER_IS_USER(u->manager) &&
                     (ec->syscall_whitelist ||
                      !set_isempty(ec->syscall_filter) ||
                      !set_isempty(ec->syscall_archs) ||
@@ -3318,7 +3318,7 @@ ExecRuntime *unit_get_exec_runtime(Unit *u) {
 static int unit_drop_in_dir(Unit *u, UnitSetPropertiesMode mode, bool transient, char **dir) {
         assert(u);
 
-        if (u->manager->running_as == MANAGER_USER) {
+        if (MANAGER_IS_USER(u->manager)) {
                 int r;
 
                 if (mode == UNIT_PERSISTENT && !transient)
index 2cec6ba76f8416d78f1a252a2d293635d995e9a2..f80234339918e736e0b44fd8fd3bddb10f75a9d4 100644 (file)
@@ -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;
 
index 5766053cefd50bfeab2a21bc0690bc17598b0e9f..cfe62c6438799bb34f11a810acb23a83b250b156 100644 (file)
@@ -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);
-}
index 64c8035c2bfebfdaae4ca38bcdacdafd86a885f8..974db79509573e6d64bef437367d189aafd2029a 100644 (file)
@@ -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)
index bab34986e32b66e0135f60cedc8b55453e80c196..3fd44a01d4a3c6c99b0f558fafd1b7d9b7e0c5c8 100644 (file)
@@ -4810,7 +4810,7 @@ static int cat(int argc, char *argv[], void *userdata) {
                 return -EINVAL;
         }
 
-        r = lookup_paths_init_from_scope(&lp, arg_scope, arg_root);
+        r = lookup_paths_init(&lp, arg_scope, arg_root);
         if (r < 0)
                 return log_error_errno(r, "Failed to determine unit paths: %m");
 
@@ -5241,7 +5241,7 @@ static int enable_sysv_units(const char *verb, char **args) {
         /* Processes all SysV units, and reshuffles the array so that
          * afterwards only the native units remain */
 
-        r = lookup_paths_init(&paths, MANAGER_SYSTEM, false, arg_root);
+        r = lookup_paths_init(&paths, arg_scope, arg_root);
         if (r < 0)
                 return r;
 
@@ -6074,7 +6074,7 @@ static int find_paths_to_edit(sd_bus *bus, char **names, char ***paths) {
         assert(names);
         assert(paths);
 
-        r = lookup_paths_init_from_scope(&lp, arg_scope, arg_root);
+        r = lookup_paths_init(&lp, arg_scope, arg_root);
         if (r < 0)
                 return r;
 
index b82c877dc782227f09138a845f81a050f5adc300..3f5f24b4b9230fd968f10ef3657797f2b9e0fcd0 100644 (file)
@@ -1004,7 +1004,7 @@ int main(int argc, char *argv[]) {
 
         umask(0022);
 
-        r = lookup_paths_init(&lp, MANAGER_SYSTEM, true, NULL);
+        r = lookup_paths_init(&lp, UNIT_FILE_SYSTEM, NULL);
         if (r < 0) {
                 log_error_errno(r, "Failed to find lookup paths: %m");
                 goto finish;
index ad15075a5b49d55f987d7f024891ffbbdebddbda..332755cf41162eb4609f0bd132f0a2be5c50d87c 100644 (file)
@@ -33,7 +33,7 @@ static int test_cgroup_mask(void) {
 
         /* Prepare the manager. */
         assert_se(set_unit_path(TEST_DIR) >= 0);
-        r = manager_new(MANAGER_USER, true, &m);
+        r = manager_new(UNIT_FILE_USER, true, &m);
         if (r == -EPERM || r == -EACCES) {
                 puts("manager_new: Permission denied. Skipping test.");
                 return EXIT_TEST_SKIP;
index ca66f5b684693e7464b4131565962fd0cd48a1d1..52b34c03df8b0d581d16a3d0eab3b586819d351c 100644 (file)
@@ -36,7 +36,7 @@ int main(int argc, char *argv[]) {
 
         /* prepare the test */
         assert_se(set_unit_path(TEST_DIR) >= 0);
-        r = manager_new(MANAGER_USER, true, &m);
+        r = manager_new(UNIT_FILE_USER, true, &m);
         if (MANAGER_SKIP_TEST(r)) {
                 printf("Skipping test: manager_new: %s\n", strerror(-r));
                 return EXIT_TEST_SKIP;
index 901cc44af6d284d9598ea927fdb5c379d5776189..77ef4e8b2acf1cc3e3bff4c041baa40506ffa511 100644 (file)
@@ -291,14 +291,14 @@ static void test_exec_spec_interpolation(Manager *m) {
         test(m, "exec-spec-interpolation.service", 0, CLD_EXITED);
 }
 
-static int run_tests(ManagerRunningAs running_as, test_function_t *tests) {
+static int run_tests(UnitFileScope scope, test_function_t *tests) {
         test_function_t *test = NULL;
         Manager *m = NULL;
         int r;
 
         assert_se(tests);
 
-        r = manager_new(running_as, true, &m);
+        r = manager_new(scope, true, &m);
         if (MANAGER_SKIP_TEST(r)) {
                 printf("Skipping test: manager_new: %s\n", strerror(-r));
                 return EXIT_TEST_SKIP;
@@ -366,9 +366,9 @@ int main(int argc, char *argv[]) {
         assert_se(unsetenv("VAR2") == 0);
         assert_se(unsetenv("VAR3") == 0);
 
-        r = run_tests(MANAGER_USER, user_tests);
+        r = run_tests(UNIT_FILE_USER, user_tests);
         if (r != 0)
                 return r;
 
-        return run_tests(MANAGER_SYSTEM, system_tests);
+        return run_tests(UNIT_FILE_SYSTEM, system_tests);
 }
index ebb11dcb6d94d7f01d8bd143e0c7b00e1a3b04bb..5575a364f29d9a0234290399020b5b50671ca9bc 100644 (file)
@@ -26,7 +26,7 @@
 #include "string-util.h"
 #include "strv.h"
 
-static void test_paths(ManagerRunningAs running_as, bool personal) {
+static void test_paths(UnitFileScope scope) {
         char template[] = "/tmp/test-path-lookup.XXXXXXX";
 
         _cleanup_lookup_paths_free_ LookupPaths lp_without_env = {};
@@ -36,26 +36,26 @@ static void test_paths(ManagerRunningAs running_as, bool personal) {
         assert_se(mkdtemp(template));
 
         assert_se(unsetenv("SYSTEMD_UNIT_PATH") == 0);
-        assert_se(lookup_paths_init(&lp_without_env, running_as, personal, NULL) == 0);
+        assert_se(lookup_paths_init(&lp_without_env, scope, NULL) == 0);
 
         assert_se(!strv_isempty(lp_without_env.search_path));
 
         systemd_unit_path = strjoina(template, "/systemd-unit-path");
         assert_se(setenv("SYSTEMD_UNIT_PATH", systemd_unit_path, 1) == 0);
-        assert_se(lookup_paths_init(&lp_with_env, running_as, personal, NULL) == 0);
+        assert_se(lookup_paths_init(&lp_with_env, scope, NULL) == 0);
         assert_se(strv_length(lp_with_env.search_path) == 1);
         assert_se(streq(lp_with_env.search_path[0], systemd_unit_path));
 
         assert_se(rm_rf(template, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
 }
 
-static void print_generator_paths(ManagerRunningAs running_as) {
+static void print_generator_paths(UnitFileScope scope) {
         _cleanup_strv_free_ char **paths;
         char **dir;
 
-        log_info("Generators dirs (%s):", running_as == MANAGER_SYSTEM ? "system" : "user");
+        log_info("Generators dirs (%s):", scope == UNIT_FILE_SYSTEM ? "system" : "user");
 
-        paths = generator_paths(running_as);
+        paths = generator_paths(scope);
         STRV_FOREACH(dir, paths)
                 log_info("        %s", *dir);
 }
@@ -65,13 +65,12 @@ int main(int argc, char **argv) {
         log_parse_environment();
         log_open();
 
-        test_paths(MANAGER_SYSTEM, false);
-        test_paths(MANAGER_SYSTEM, true);
-        test_paths(MANAGER_USER, false);
-        test_paths(MANAGER_USER, true);
+        test_paths(UNIT_FILE_SYSTEM);
+        test_paths(UNIT_FILE_USER);
+        test_paths(UNIT_FILE_GLOBAL);
 
-        print_generator_paths(MANAGER_SYSTEM);
-        print_generator_paths(MANAGER_USER);
+        print_generator_paths(UNIT_FILE_SYSTEM);
+        print_generator_paths(UNIT_FILE_USER);
 
         return EXIT_SUCCESS;
 }
index 1e704a03dc1d8b4f1a5a1d77afdd898ad6ed0bba..e0c8db50ae866a78eb7658571055a6d588a97a4b 100644 (file)
@@ -44,7 +44,7 @@ static int setup_test(Manager **m) {
 
         assert_se(m);
 
-        r = manager_new(MANAGER_USER, true, &tmp);
+        r = manager_new(UNIT_FILE_USER, true, &tmp);
         if (MANAGER_SKIP_TEST(r)) {
                 printf("Skipping test: manager_new: %s\n", strerror(-r));
                 return -EXIT_TEST_SKIP;
index 7f515b53d878ca8bf7b2131313966ca75420cc96..5083cd53c238680df705a33145bb84860878971b 100644 (file)
@@ -33,7 +33,7 @@ int main(int argc, char *argv[]) {
 
         /* prepare the test */
         assert_se(set_unit_path(TEST_DIR) >= 0);
-        r = manager_new(MANAGER_USER, true, &m);
+        r = manager_new(UNIT_FILE_USER, true, &m);
         if (MANAGER_SKIP_TEST(r)) {
                 printf("Skipping test: manager_new: %s\n", strerror(-r));
                 return EXIT_TEST_SKIP;
index cc6c61ba634cd3d632ac374e8392e9c14e428a76..7f2fee772ba64717d73353c5a12d0eb3175f4303 100644 (file)
@@ -113,7 +113,7 @@ static void test_config_parse_exec(void) {
         Manager *m = NULL;
         Unit *u = NULL;
 
-        r = manager_new(MANAGER_USER, true, &m);
+        r = manager_new(UNIT_FILE_USER, true, &m);
         if (MANAGER_SKIP_TEST(r)) {
                 printf("Skipping test: manager_new: %s\n", strerror(-r));
                 return;
index 3de94ef4253e46cecdc378aa2b3f3883c16ed14c..2fd83f321cec6d0a23a031b4a44cd3caf802e622 100644 (file)
@@ -209,7 +209,7 @@ static int test_unit_printf(void) {
         assert_se(get_home_dir(&home) >= 0);
         assert_se(get_shell(&shell) >= 0);
 
-        r = manager_new(MANAGER_USER, true, &m);
+        r = manager_new(UNIT_FILE_USER, true, &m);
         if (r == -EPERM || r == -EACCES || r == -EADDRINUSE) {
                 puts("manager_new: Permission denied. Skipping test.");
                 return EXIT_TEST_SKIP;