X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fcore%2Fmanager.c;h=0653d7e59aa4ce54fee137201ab63e014dee4153;hp=360a65a49219da98b49f5a2fc3dd8278b7291237;hb=1cd974edfd7cd91dcdf321e7202bd220bac50a2d;hpb=6a0f1f6d5af7c7300d3db7a0ba2b068f8abd222b diff --git a/src/core/manager.c b/src/core/manager.c index 360a65a49..0653d7e59 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -225,8 +225,8 @@ static int manager_watch_idle_pipe(Manager *m) { static void manager_close_idle_pipe(Manager *m) { assert(m); - close_pipe(m->idle_pipe); - close_pipe(m->idle_pipe + 2); + safe_close_pair(m->idle_pipe); + safe_close_pair(m->idle_pipe + 2); } static int manager_setup_time_change(Manager *m) { @@ -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; @@ -422,18 +428,21 @@ int manager_new(SystemdRunningAs running_as, Manager **_m) { return -ENOMEM; #ifdef ENABLE_EFI - if (detect_container(NULL) <= 0) + if (running_as == SYSTEMD_SYSTEM && detect_container(NULL) <= 0) boot_timestamps(&m->userspace_timestamp, &m->firmware_timestamp, &m->loader_timestamp); #endif m->running_as = running_as; m->exit_code = _MANAGER_EXIT_CODE_INVALID; + m->default_timer_accuracy_usec = USEC_PER_MINUTE; m->idle_pipe[0] = m->idle_pipe[1] = m->idle_pipe[2] = m->idle_pipe[3] = -1; 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; @@ -454,6 +463,10 @@ int manager_new(SystemdRunningAs running_as, Manager **_m) { if (r < 0) goto fail; + r = set_ensure_allocated(&m->startup_units, trivial_hash_func, trivial_compare_func); + if (r < 0) + goto fail; + r = set_ensure_allocated(&m->failed_units, trivial_hash_func, trivial_compare_func); if (r < 0) goto fail; @@ -509,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 { @@ -549,7 +565,7 @@ static int manager_setup_notify(Manager *m) { strncpy(sa.un.sun_path, m->notify_socket, sizeof(sa.un.sun_path)-1); r = bind(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path)); if (r < 0) { - log_error("bind() failed: %m"); + log_error("bind(@%s) failed: %m", sa.un.sun_path+1); return -errno; } @@ -587,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); @@ -619,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 || @@ -792,6 +809,7 @@ void manager_free(Manager *m) { hashmap_free(m->watch_pids2); hashmap_free(m->watch_bus); + set_free(m->startup_units); set_free(m->failed_units); sd_event_source_unref(m->signal_event_source); @@ -966,6 +984,7 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) { r = lookup_paths_init( &m->lookup_paths, m->running_as, true, + NULL, m->generator_unit_path, m->generator_unit_path_early, m->generator_unit_path_late); @@ -986,11 +1005,8 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) { dual_timestamp_get(&m->units_load_finish_timestamp); /* Second, deserialize if there is something to deserialize */ - if (serialization) { - q = manager_deserialize(m, serialization, fds); - if (q < 0) - r = q; - } + if (serialization) + r = manager_deserialize(m, serialization, fds); /* Any fds left? Find some unit which wants them. This is * useful to allow container managers to pass some file @@ -998,13 +1014,15 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) { * socket-based activation of entire containers. */ if (fdset_size(fds) > 0) { q = manager_distribute_fds(m, fds); - if (q < 0) + if (q < 0 && r == 0) r = q; } /* We might have deserialized the notify fd, but if we didn't * then let's create the bus now */ - manager_setup_notify(m); + q = manager_setup_notify(m); + if (q < 0 && r == 0) + r = q; /* We might have deserialized the kdbus control fd, but if we * didn't, then let's create the bus now. */ @@ -1014,7 +1032,7 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) { /* Third, fire things up! */ q = manager_coldplug(m); - if (q < 0) + if (q < 0 && r == 0) r = q; if (serialization) { @@ -2128,9 +2146,6 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root) { if (u->id != t) continue; - if (!unit_can_serialize(u)) - continue; - /* Start marker */ fputs(u->id, f); fputc('\n', f); @@ -2372,6 +2387,7 @@ int manager_reload(Manager *m) { q = lookup_paths_init( &m->lookup_paths, m->running_as, true, + NULL, m->generator_unit_path, m->generator_unit_path_early, m->generator_unit_path_late); @@ -2444,6 +2460,8 @@ bool manager_unit_inactive_or_pending(Manager *m, const char *name) { void manager_check_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; + Unit *u = NULL; + Iterator i; assert(m); @@ -2469,6 +2487,9 @@ void manager_check_finished(Manager *m) { /* Turn off confirm spawn now */ m->confirm_spawn = false; + /* This is no longer the first boot */ + manager_set_first_boot(m, false); + if (dual_timestamp_is_set(&m->finish_timestamp)) return; @@ -2531,6 +2552,10 @@ void manager_check_finished(Manager *m) { NULL); } + SET_FOREACH(u, m->startup_units, i) + if (u->cgroup_path) + cgroup_context_apply(unit_get_cgroup_context(u), unit_get_cgroup_mask(u), u->cgroup_path, manager_state(m)); + bus_manager_send_finished(m, firmware_usec, loader_usec, kernel_usec, initrd_usec, userspace_usec, total_usec); sd_notifyf(false, @@ -2622,6 +2647,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) { @@ -2796,6 +2824,20 @@ static bool manager_get_show_status(Manager *m) { return plymouth_running(); } +void manager_set_first_boot(Manager *m, bool b) { + assert(m); + + if (m->running_as != SYSTEMD_SYSTEM) + return; + + m->first_boot = b; + + if (m->first_boot) + touch("/run/systemd/first-boot"); + else + unlink("/run/systemd/first-boot"); +} + void manager_status_printf(Manager *m, bool ephemeral, const char *status, const char *format, ...) { va_list ap;