diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-01-07 08:41:24 -0500 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-07-20 19:48:16 -0400 |
commit | 0d8c31ff7237149b505290652864b4e7e866b2a7 (patch) | |
tree | 2a1497d3b0384fb7ab20c6010276be0e166619eb /src/core | |
parent | f0ea29eaeb3449822bfbdfa839b00e323dfc523e (diff) |
test-engine: fix access to unit load path
Also add a bit of debugging output to help diagnose problems,
add missing units, and simplify cppflags.
Move test-engine to normal tests from manual tests, it should now
work without destroying the system.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/cgroup.c | 57 | ||||
-rw-r--r-- | src/core/main.c | 11 | ||||
-rw-r--r-- | src/core/manager.c | 23 | ||||
-rw-r--r-- | src/core/manager.h | 4 |
4 files changed, 60 insertions, 35 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c index cd6796383b..db8b4d7705 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -832,7 +832,6 @@ pid_t unit_search_main_pid(Unit *u) { int manager_setup_cgroup(Manager *m) { _cleanup_free_ char *path = NULL; - char *e; int r; assert(m); @@ -851,6 +850,8 @@ int manager_setup_cgroup(Manager *m) { * off. This is to support live upgrades from older systemd * versions where PID 1 was moved there. */ if (m->running_as == SYSTEMD_SYSTEM) { + char *e; + e = endswith(m->cgroup_root, "/" SPECIAL_SYSTEM_SLICE); if (!e) e = endswith(m->cgroup_root, "/system"); @@ -872,40 +873,42 @@ int manager_setup_cgroup(Manager *m) { } log_debug("Using cgroup controller " SYSTEMD_CGROUP_CONTROLLER ". File system hierarchy is at %s.", path); + if (!m->test_run) { - /* 3. Install agent */ - if (m->running_as == SYSTEMD_SYSTEM) { - r = cg_install_release_agent(SYSTEMD_CGROUP_CONTROLLER, SYSTEMD_CGROUP_AGENT_PATH); - if (r < 0) - log_warning("Failed to install release agent, ignoring: %s", strerror(-r)); - else if (r > 0) - log_debug("Installed release agent."); - else - log_debug("Release agent already installed."); - } + /* 3. Install agent */ + if (m->running_as == SYSTEMD_SYSTEM) { + r = cg_install_release_agent(SYSTEMD_CGROUP_CONTROLLER, SYSTEMD_CGROUP_AGENT_PATH); + if (r < 0) + log_warning("Failed to install release agent, ignoring: %s", strerror(-r)); + else if (r > 0) + log_debug("Installed release agent."); + else + log_debug("Release agent already installed."); + } - /* 4. Make sure we are in the root cgroup */ - r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_root, 0); - if (r < 0) { - log_error("Failed to create root cgroup hierarchy: %s", strerror(-r)); - return r; - } + /* 4. Make sure we are in the root cgroup */ + r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_root, 0); + if (r < 0) { + log_error("Failed to create root cgroup hierarchy: %s", strerror(-r)); + return r; + } - /* 5. And pin it, so that it cannot be unmounted */ - safe_close(m->pin_cgroupfs_fd); + /* 5. And pin it, so that it cannot be unmounted */ + safe_close(m->pin_cgroupfs_fd); - m->pin_cgroupfs_fd = open(path, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOCTTY|O_NONBLOCK); - if (m->pin_cgroupfs_fd < 0) { - log_error("Failed to open pin file: %m"); - return -errno; + m->pin_cgroupfs_fd = open(path, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOCTTY|O_NONBLOCK); + if (m->pin_cgroupfs_fd < 0) { + log_error("Failed to open pin file: %m"); + return -errno; + } + + /* 6. Always enable hierarchial support if it exists... */ + cg_set_attribute("memory", "/", "memory.use_hierarchy", "1"); } - /* 6. Figure out which controllers are supported */ + /* 7. Figure out which controllers are supported */ m->cgroup_supported = cg_mask_supported(); - /* 7. Always enable hierarchial support if it exists... */ - cg_set_attribute("memory", "/", "memory.use_hierarchy", "1"); - return 0; } diff --git a/src/core/main.c b/src/core/main.c index ae38b435d9..29f97364a4 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1473,6 +1473,9 @@ int main(int argc, char *argv[]) { goto finish; } + if (arg_action == ACTION_TEST) + skip_setup = true; + pager_open_if_enabled(); if (arg_action == ACTION_HELP) { @@ -1543,7 +1546,8 @@ int main(int argc, char *argv[]) { if (arg_running_as == SYSTEMD_SYSTEM) { const char *virtualization = NULL; - log_info(PACKAGE_STRING " running in system mode. (" SYSTEMD_FEATURES ")"); + log_info(PACKAGE_STRING " running in %ssystem mode. (" SYSTEMD_FEATURES ")", + arg_action == ACTION_TEST ? "test " : "" ); detect_virtualization(&virtualization); if (virtualization) @@ -1571,7 +1575,8 @@ int main(int argc, char *argv[]) { _cleanup_free_ char *t; t = uid_to_name(getuid()); - log_debug(PACKAGE_STRING " running in user mode for user "UID_FMT"/%s. (" SYSTEMD_FEATURES ")", getuid(), strna(t)); + log_debug(PACKAGE_STRING " running in %suser mode for user "UID_FMT"/%s. (" SYSTEMD_FEATURES ")", + arg_action == ACTION_TEST ? " test" : "", getuid(), t); } if (arg_running_as == SYSTEMD_SYSTEM && !skip_setup) { @@ -1636,7 +1641,7 @@ int main(int argc, char *argv[]) { } } - r = manager_new(arg_running_as, &m); + r = manager_new(arg_running_as, arg_action == ACTION_TEST, &m); if (r < 0) { log_error("Failed to allocate manager object: %s", strerror(-r)); goto finish; diff --git a/src/core/manager.c b/src/core/manager.c index 9d9a713005..2e63c5ef1f 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -241,6 +241,9 @@ static int manager_setup_time_change(Manager *m) { assert(m); assert_cc(sizeof(time_t) == sizeof(TIME_T_MAX)); + if (m->test_run) + return 0; + /* Uses TFD_TIMER_CANCEL_ON_SET to get notifications whenever * CLOCK_REALTIME makes a jump relative to CLOCK_MONOTONIC */ @@ -302,6 +305,9 @@ static int manager_setup_signals(Manager *m) { assert(m); + if (m->test_run) + return 0; + /* We are not interested in SIGSTOP and friends. */ assert_se(sigaction(SIGCHLD, &sa, NULL) == 0); @@ -409,7 +415,7 @@ static int manager_default_environment(Manager *m) { return 0; } -int manager_new(SystemdRunningAs running_as, Manager **_m) { +int manager_new(SystemdRunningAs running_as, bool test_run, Manager **_m) { Manager *m; int r; @@ -435,6 +441,8 @@ int manager_new(SystemdRunningAs running_as, Manager **_m) { m->pin_cgroupfs_fd = m->notify_fd = m->signal_fd = m->time_change_fd = m->dev_autofs_fd = m->private_listen_fd = m->kdbus_fd = -1; m->current_job_id = 1; /* start as id #1, so that we can leave #0 around as "null-like" value */ + m->test_run = test_run; + r = manager_default_environment(m); if (r < 0) goto fail; @@ -514,6 +522,9 @@ fail: static int manager_setup_notify(Manager *m) { int r; + if (m->test_run) + return 0; + if (m->notify_fd < 0) { _cleanup_close_ int fd = -1; union { @@ -592,12 +603,10 @@ static int manager_setup_notify(Manager *m) { static int manager_setup_kdbus(Manager *m) { #ifdef ENABLE_KDBUS _cleanup_free_ char *p = NULL; -#endif -#ifdef ENABLE_KDBUS assert(m); - if (m->kdbus_fd >= 0) + if (m->test_run || m->kdbus_fd >= 0) return 0; m->kdbus_fd = bus_kernel_create_bus(m->running_as == SYSTEMD_SYSTEM ? "system" : "user", m->running_as == SYSTEMD_SYSTEM, &p); @@ -624,6 +633,9 @@ static int manager_connect_bus(Manager *m, bool reexecuting) { assert(m); + if (m->test_run) + return 0; + try_bus_connect = m->kdbus_fd >= 0 || reexecuting || @@ -2636,6 +2648,9 @@ void manager_run_generators(Manager *m) { assert(m); + if (m->test_run) + return; + generator_path = m->running_as == SYSTEMD_SYSTEM ? SYSTEM_GENERATOR_PATH : USER_GENERATOR_PATH; d = opendir(generator_path); if (!d) { diff --git a/src/core/manager.h b/src/core/manager.h index 718c29fa0f..aa6c76fa5a 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -230,6 +230,8 @@ struct Manager { bool taint_usr:1; bool first_boot:1; + bool test_run:1; + ShowStatus show_status; bool confirm_spawn; bool no_console_output; @@ -276,7 +278,7 @@ struct Manager { int kdbus_fd; }; -int manager_new(SystemdRunningAs running_as, Manager **m); +int manager_new(SystemdRunningAs running_as, bool test_run, Manager **m); void manager_free(Manager *m); int manager_enumerate(Manager *m); |