Make test_run into a flags field and disable generators again
Now generators are only run in systemd --test mode, where this makes most sense (how are you going to test what would happen otherwise?). Fixes #6842. v2: - rename test_run to test_run_flags
This commit is contained in:
parent
d75b31837c
commit
e0a3da1fd2
|
@ -264,7 +264,7 @@ int verify_units(char **filenames, UnitFileScope scope, bool check_man) {
|
|||
|
||||
assert_se(set_unit_path(var) >= 0);
|
||||
|
||||
r = manager_new(scope, true, &m);
|
||||
r = manager_new(scope, MANAGER_TEST_RUN_ENV_GENERATORS, &m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to initialize manager: %m");
|
||||
|
||||
|
|
|
@ -1813,7 +1813,7 @@ int manager_setup_cgroup(Manager *m) {
|
|||
log_debug("Using cgroup controller " SYSTEMD_CGROUP_CONTROLLER_LEGACY ". File system hierarchy is at %s.", path);
|
||||
}
|
||||
|
||||
if (!m->test_run) {
|
||||
if (!m->test_run_flags) {
|
||||
const char *scope_path;
|
||||
|
||||
/* 3. Install agent */
|
||||
|
|
|
@ -1817,7 +1817,9 @@ int main(int argc, char *argv[]) {
|
|||
(void) bump_rlimit_nofile(&saved_rlimit_nofile);
|
||||
}
|
||||
|
||||
r = manager_new(arg_system ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, arg_action == ACTION_TEST, &m);
|
||||
r = manager_new(arg_system ? UNIT_FILE_SYSTEM : UNIT_FILE_USER,
|
||||
arg_action == ACTION_TEST ? MANAGER_TEST_FULL : 0,
|
||||
&m);
|
||||
if (r < 0) {
|
||||
log_emergency_errno(r, "Failed to allocate manager object: %m");
|
||||
error_message = "Failed to allocate manager object";
|
||||
|
|
|
@ -358,7 +358,7 @@ static int manager_setup_time_change(Manager *m) {
|
|||
assert(m);
|
||||
assert_cc(sizeof(time_t) == sizeof(TIME_T_MAX));
|
||||
|
||||
if (m->test_run)
|
||||
if (m->test_run_flags)
|
||||
return 0;
|
||||
|
||||
/* Uses TFD_TIMER_CANCEL_ON_SET to get notifications whenever
|
||||
|
@ -390,7 +390,7 @@ static int enable_special_signals(Manager *m) {
|
|||
|
||||
assert(m);
|
||||
|
||||
if (m->test_run)
|
||||
if (m->test_run_flags)
|
||||
return 0;
|
||||
|
||||
/* Enable that we get SIGINT on control-alt-del. In containers
|
||||
|
@ -600,7 +600,7 @@ static int manager_setup_prefix(Manager *m) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int manager_new(UnitFileScope scope, bool test_run, Manager **_m) {
|
||||
int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **_m) {
|
||||
Manager *m;
|
||||
int r;
|
||||
|
||||
|
@ -650,7 +650,7 @@ int manager_new(UnitFileScope scope, bool test_run, Manager **_m) {
|
|||
m->have_ask_password = -EINVAL; /* we don't know */
|
||||
m->first_boot = -1;
|
||||
|
||||
m->test_run = test_run;
|
||||
m->test_run_flags = test_run_flags;
|
||||
|
||||
/* Reboot immediately if the user hits C-A-D more often than 7x per 2s */
|
||||
RATELIMIT_INIT(m->ctrl_alt_del_ratelimit, 2 * USEC_PER_SEC, 7);
|
||||
|
@ -731,7 +731,7 @@ fail:
|
|||
static int manager_setup_notify(Manager *m) {
|
||||
int r;
|
||||
|
||||
if (m->test_run)
|
||||
if (m->test_run_flags)
|
||||
return 0;
|
||||
|
||||
if (m->notify_fd < 0) {
|
||||
|
@ -811,7 +811,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)
|
||||
if (m->test_run_flags)
|
||||
return 0;
|
||||
|
||||
if (!MANAGER_IS_SYSTEM(m))
|
||||
|
@ -925,7 +925,7 @@ static int manager_connect_bus(Manager *m, bool reexecuting) {
|
|||
|
||||
assert(m);
|
||||
|
||||
if (m->test_run)
|
||||
if (m->test_run_flags)
|
||||
return 0;
|
||||
|
||||
u = manager_get_unit(m, SPECIAL_DBUS_SERVICE);
|
||||
|
@ -1313,7 +1313,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 ? LOOKUP_PATHS_TEMPORARY_GENERATED : 0,
|
||||
m->test_run_flags ? LOOKUP_PATHS_TEMPORARY_GENERATED : 0,
|
||||
NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
@ -1336,7 +1336,7 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
|
|||
|
||||
if (m->first_boot > 0 &&
|
||||
m->unit_file_scope == UNIT_FILE_SYSTEM &&
|
||||
!m->test_run) {
|
||||
!m->test_run_flags) {
|
||||
|
||||
q = unit_file_preset_all(UNIT_FILE_SYSTEM, 0, NULL, UNIT_FILE_PRESET_ENABLE_ONLY, NULL, 0);
|
||||
if (q < 0)
|
||||
|
@ -3003,7 +3003,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)
|
||||
if (m->test_run_flags)
|
||||
return;
|
||||
|
||||
if (MANAGER_IS_SYSTEM(m) && detect_container() <= 0) {
|
||||
|
@ -3148,6 +3148,9 @@ 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))
|
||||
return 0;
|
||||
|
||||
paths = MANAGER_IS_SYSTEM(m) ? system_env_generator_binary_paths : user_env_generator_binary_paths;
|
||||
|
||||
if (!generator_path_any(paths))
|
||||
|
@ -3163,6 +3166,9 @@ static int manager_run_generators(Manager *m) {
|
|||
|
||||
assert(m);
|
||||
|
||||
if (m->test_run_flags && !(m->test_run_flags & MANAGER_TEST_RUN_GENERATORS))
|
||||
return 0;
|
||||
|
||||
paths = generator_binary_paths(m->unit_file_scope);
|
||||
if (!paths)
|
||||
return log_oom();
|
||||
|
|
|
@ -74,6 +74,15 @@ typedef enum StatusType {
|
|||
#include "show-status.h"
|
||||
#include "unit-name.h"
|
||||
|
||||
enum {
|
||||
/* 0 = run normally */
|
||||
MANAGER_TEST_RUN_MINIMAL = 1, /* run test w/o generators */
|
||||
MANAGER_TEST_RUN_ENV_GENERATORS = 2, /* also run env generators */
|
||||
MANAGER_TEST_RUN_GENERATORS = 4, /* also run unit generators */
|
||||
MANAGER_TEST_FULL = MANAGER_TEST_RUN_ENV_GENERATORS | MANAGER_TEST_RUN_GENERATORS,
|
||||
};
|
||||
assert_cc((MANAGER_TEST_FULL & UINT8_MAX) == MANAGER_TEST_FULL);
|
||||
|
||||
struct Manager {
|
||||
/* Note that the set of units we know of is allowed to be
|
||||
* inconsistent. However the subset of it that is loaded may
|
||||
|
@ -238,7 +247,8 @@ struct Manager {
|
|||
bool dispatching_dbus_queue:1;
|
||||
|
||||
bool taint_usr:1;
|
||||
bool test_run:1;
|
||||
|
||||
unsigned test_run_flags:8;
|
||||
|
||||
/* If non-zero, exit with the following value when the systemd
|
||||
* process terminate. Useful for containers: systemd-nspawn could get
|
||||
|
@ -326,7 +336,7 @@ struct Manager {
|
|||
|
||||
#define MANAGER_IS_RELOADING(m) ((m)->n_reloading > 0)
|
||||
|
||||
int manager_new(UnitFileScope scope, bool test_run, Manager **m);
|
||||
int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **m);
|
||||
Manager* manager_free(Manager *m);
|
||||
|
||||
void manager_enumerate(Manager *m);
|
||||
|
|
|
@ -39,7 +39,7 @@ static int test_cgroup_mask(void) {
|
|||
/* Prepare the manager. */
|
||||
assert_se(set_unit_path(get_testdata_dir("")) >= 0);
|
||||
assert_se(runtime_dir = setup_fake_runtime_dir());
|
||||
r = manager_new(UNIT_FILE_USER, true, &m);
|
||||
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_MINIMAL, &m);
|
||||
if (r == -EPERM || r == -EACCES) {
|
||||
puts("manager_new: Permission denied. Skipping test.");
|
||||
return EXIT_TEST_SKIP;
|
||||
|
|
|
@ -42,7 +42,7 @@ int main(int argc, char *argv[]) {
|
|||
/* prepare the test */
|
||||
assert_se(set_unit_path(get_testdata_dir("")) >= 0);
|
||||
assert_se(runtime_dir = setup_fake_runtime_dir());
|
||||
r = manager_new(UNIT_FILE_USER, true, &m);
|
||||
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_MINIMAL, &m);
|
||||
if (MANAGER_SKIP_TEST(r)) {
|
||||
log_notice_errno(r, "Skipping test: manager_new: %m");
|
||||
return EXIT_TEST_SKIP;
|
||||
|
|
|
@ -464,7 +464,7 @@ static int run_tests(UnitFileScope scope, const test_function_t *tests) {
|
|||
|
||||
assert_se(tests);
|
||||
|
||||
r = manager_new(scope, true, &m);
|
||||
r = manager_new(scope, MANAGER_TEST_RUN_MINIMAL, &m);
|
||||
if (MANAGER_SKIP_TEST(r)) {
|
||||
log_notice_errno(r, "Skipping test: manager_new: %m");
|
||||
return EXIT_TEST_SKIP;
|
||||
|
|
|
@ -47,7 +47,7 @@ static int setup_test(Manager **m) {
|
|||
|
||||
enter_cgroup_subroot();
|
||||
|
||||
r = manager_new(UNIT_FILE_USER, true, &tmp);
|
||||
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_MINIMAL, &tmp);
|
||||
if (MANAGER_SKIP_TEST(r)) {
|
||||
log_notice_errno(r, "Skipping test: manager_new: %m");
|
||||
return -EXIT_TEST_SKIP;
|
||||
|
|
|
@ -39,7 +39,7 @@ int main(int argc, char *argv[]) {
|
|||
/* prepare the test */
|
||||
assert_se(set_unit_path(get_testdata_dir("")) >= 0);
|
||||
assert_se(runtime_dir = setup_fake_runtime_dir());
|
||||
r = manager_new(UNIT_FILE_USER, true, &m);
|
||||
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_MINIMAL, &m);
|
||||
if (MANAGER_SKIP_TEST(r)) {
|
||||
log_notice_errno(r, "Skipping test: manager_new: %m");
|
||||
return EXIT_TEST_SKIP;
|
||||
|
|
|
@ -115,7 +115,7 @@ static void test_config_parse_exec(void) {
|
|||
Manager *m = NULL;
|
||||
Unit *u = NULL;
|
||||
|
||||
r = manager_new(UNIT_FILE_USER, true, &m);
|
||||
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_MINIMAL, &m);
|
||||
if (MANAGER_SKIP_TEST(r)) {
|
||||
log_notice_errno(r, "Skipping test: manager_new: %m");
|
||||
return;
|
||||
|
|
|
@ -211,7 +211,7 @@ static int test_unit_printf(void) {
|
|||
assert_se(get_home_dir(&home) >= 0);
|
||||
assert_se(get_shell(&shell) >= 0);
|
||||
|
||||
r = manager_new(UNIT_FILE_USER, true, &m);
|
||||
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_MINIMAL, &m);
|
||||
if (MANAGER_SKIP_TEST(r)) {
|
||||
log_notice_errno(r, "Skipping test: manager_new: %m");
|
||||
return EXIT_TEST_SKIP;
|
||||
|
|
Loading…
Reference in a new issue