diff --git a/src/analyze/analyze-verify.c b/src/analyze/analyze-verify.c index ed369532d4..d2f9e5528e 100644 --- a/src/analyze/analyze-verify.c +++ b/src/analyze/analyze-verify.c @@ -225,9 +225,10 @@ static int verify_unit(Unit *u, bool check_man) { } int verify_units(char **filenames, UnitFileScope scope, bool check_man, bool run_generators) { - const uint8_t flags = MANAGER_TEST_RUN_BASIC | - MANAGER_TEST_RUN_ENV_GENERATORS | - run_generators * MANAGER_TEST_RUN_GENERATORS; + const ManagerTestRunFlags flags = + MANAGER_TEST_RUN_BASIC | + MANAGER_TEST_RUN_ENV_GENERATORS | + run_generators * MANAGER_TEST_RUN_GENERATORS; _cleanup_(manager_freep) Manager *m = NULL; Unit *units[strv_length(filenames)]; diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 7e07b2f13c..6a6766f6fa 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -2305,7 +2305,7 @@ int manager_setup_cgroup(Manager *m) { (void) sd_event_source_set_description(m->cgroup_inotify_event_source, "cgroup-inotify"); - } else if (MANAGER_IS_SYSTEM(m) && m->test_run_flags == 0) { + } else if (MANAGER_IS_SYSTEM(m) && !MANAGER_IS_TEST_RUN(m)) { /* On the legacy hierarchy we only get notifications via cgroup agents. (Which isn't really reliable, * since it does not generate events when control groups with children run empty. */ @@ -2334,11 +2334,11 @@ int manager_setup_cgroup(Manager *m) { if (m->pin_cgroupfs_fd < 0) return log_error_errno(errno, "Failed to open pin file: %m"); - } else if (!m->test_run_flags) + } else if (!MANAGER_IS_TEST_RUN(m)) return log_error_errno(r, "Failed to create %s control group: %m", scope_path); /* 7. Always enable hierarchical support if it exists... */ - if (!all_unified && m->test_run_flags == 0) + if (!all_unified && !MANAGER_IS_TEST_RUN(m)) (void) cg_set_attribute("memory", "/", "memory.use_hierarchy", "1"); /* 8. Figure out which controllers are supported, and log about it */ diff --git a/src/core/manager.c b/src/core/manager.c index d9e9dddea3..ba16e8259e 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -351,7 +351,7 @@ static int manager_setup_time_change(Manager *m) { assert(m); - if (m->test_run_flags) + if (MANAGER_IS_TEST_RUN(m)) return 0; m->time_change_event_source = sd_event_source_unref(m->time_change_event_source); @@ -407,7 +407,7 @@ static int manager_setup_timezone_change(Manager *m) { assert(m); - if (m->test_run_flags != 0) + if (MANAGER_IS_TEST_RUN(m)) return 0; /* We watch /etc/localtime for three events: change of the link count (which might mean removal from /etc even @@ -446,7 +446,7 @@ static int enable_special_signals(Manager *m) { assert(m); - if (m->test_run_flags) + if (MANAGER_IS_TEST_RUN(m)) return 0; /* Enable that we get SIGINT on control-alt-del. In containers @@ -711,7 +711,7 @@ static int manager_setup_sigchld_event_source(Manager *m) { return 0; } -int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **_m) { +int manager_new(UnitFileScope scope, ManagerTestRunFlags test_run_flags, Manager **_m) { _cleanup_(manager_freep) Manager *m = NULL; int r; @@ -865,7 +865,7 @@ int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **_m) { static int manager_setup_notify(Manager *m) { int r; - if (m->test_run_flags) + if (MANAGER_IS_TEST_RUN(m)) return 0; if (m->notify_fd < 0) { @@ -944,7 +944,7 @@ static int manager_setup_cgroups_agent(Manager *m) { * to it. The system instance hence listens on this special socket, but the user instances listen on the system * bus for these messages. */ - if (m->test_run_flags) + if (MANAGER_IS_TEST_RUN(m)) return 0; if (!MANAGER_IS_SYSTEM(m)) @@ -1521,7 +1521,7 @@ static bool manager_dbus_is_running(Manager *m, bool deserialized) { * and the service unit. If the 'deserialized' parameter is true we'll check the deserialized state of the unit * rather than the current one. */ - if (m->test_run_flags != 0) + if (MANAGER_IS_TEST_RUN(m)) return false; u = manager_get_unit(m, SPECIAL_DBUS_SOCKET); @@ -1569,7 +1569,7 @@ static void manager_preset_all(Manager *m) { if (!MANAGER_IS_SYSTEM(m)) return; - if (m->test_run_flags != 0) + if (MANAGER_IS_TEST_RUN(m)) return; /* If this is the first boot, and we are in the host system, then preset everything */ @@ -1589,7 +1589,7 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) { /* If we are running in test mode, we still want to run the generators, * but we should not touch the real generator directories. */ r = lookup_paths_init(&m->lookup_paths, m->unit_file_scope, - m->test_run_flags ? LOOKUP_PATHS_TEMPORARY_GENERATED : 0, + MANAGER_IS_TEST_RUN(m) ? LOOKUP_PATHS_TEMPORARY_GENERATED : 0, NULL); if (r < 0) return r; @@ -3593,7 +3593,7 @@ static void manager_notify_finished(Manager *m) { char userspace[FORMAT_TIMESPAN_MAX], initrd[FORMAT_TIMESPAN_MAX], kernel[FORMAT_TIMESPAN_MAX], sum[FORMAT_TIMESPAN_MAX]; usec_t firmware_usec, loader_usec, kernel_usec, initrd_usec, userspace_usec, total_usec; - if (m->test_run_flags) + if (MANAGER_IS_TEST_RUN(m)) return; if (MANAGER_IS_SYSTEM(m) && detect_container() <= 0) { @@ -3788,7 +3788,7 @@ static int manager_run_environment_generators(Manager *m) { const char **paths; void* args[] = {&tmp, &tmp, &m->environment}; - if (m->test_run_flags && !(m->test_run_flags & MANAGER_TEST_RUN_ENV_GENERATORS)) + if (MANAGER_IS_TEST_RUN(m) && !(m->test_run_flags & MANAGER_TEST_RUN_ENV_GENERATORS)) return 0; paths = MANAGER_IS_SYSTEM(m) ? system_env_generator_binary_paths : user_env_generator_binary_paths; @@ -3806,7 +3806,7 @@ static int manager_run_generators(Manager *m) { assert(m); - if (m->test_run_flags && !(m->test_run_flags & MANAGER_TEST_RUN_GENERATORS)) + if (MANAGER_IS_TEST_RUN(m) && !(m->test_run_flags & MANAGER_TEST_RUN_GENERATORS)) return 0; paths = generator_binary_paths(m->unit_file_scope); @@ -3920,7 +3920,7 @@ static bool manager_journal_is_running(Manager *m) { assert(m); - if (m->test_run_flags != 0) + if (MANAGER_IS_TEST_RUN(m)) return false; /* If we are the user manager we can safely assume that the journal is up */ diff --git a/src/core/manager.h b/src/core/manager.h index 13110b3b63..6e6e251a55 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -108,14 +108,15 @@ typedef enum ManagerTimestamp { #include "show-status.h" #include "unit-name.h" -enum { - /* 0 = run normally */ +typedef enum ManagerTestRunFlags { + MANAGER_TEST_NORMAL = 0, /* run normally */ MANAGER_TEST_RUN_MINIMAL = 1 << 0, /* create basic data structures */ MANAGER_TEST_RUN_BASIC = 1 << 1, /* interact with the environment */ MANAGER_TEST_RUN_ENV_GENERATORS = 1 << 2, /* also run env generators */ MANAGER_TEST_RUN_GENERATORS = 1 << 3, /* also run unit generators */ MANAGER_TEST_FULL = MANAGER_TEST_RUN_BASIC | MANAGER_TEST_RUN_ENV_GENERATORS | MANAGER_TEST_RUN_GENERATORS, -}; +} ManagerTestRunFlags; + assert_cc((MANAGER_TEST_FULL & UINT8_MAX) == MANAGER_TEST_FULL); struct Manager { @@ -299,7 +300,7 @@ struct Manager { /* Have we ever changed the "kernel.pid_max" sysctl? */ bool sysctl_pid_max_changed:1; - unsigned test_run_flags:8; + ManagerTestRunFlags test_run_flags:8; /* If non-zero, exit with the following value when the systemd * process terminate. Useful for containers: systemd-nspawn could get @@ -410,7 +411,9 @@ struct Manager { /* The objective is set to OK as soon as we enter the main loop, and set otherwise as soon as we are done with it */ #define MANAGER_IS_RUNNING(m) ((m)->objective == MANAGER_OK) -int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **m); +#define MANAGER_IS_TEST_RUN(m) ((m)->test_run_flags != 0) + +int manager_new(UnitFileScope scope, ManagerTestRunFlags test_run_flags, Manager **m); Manager* manager_free(Manager *m); DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free); diff --git a/src/core/unit.c b/src/core/unit.c index 853db527f7..db5dd3e884 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -5283,7 +5283,7 @@ void unit_export_state_files(Unit *u) { if (!MANAGER_IS_SYSTEM(u->manager)) return; - if (u->manager->test_run_flags != 0) + if (MANAGER_IS_TEST_RUN(u->manager)) return; /* Exports a couple of unit properties to /run/systemd/units/, so that journald can quickly query this data