X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fcore%2Fmanager.c;h=6ba51a41162c64f42dd1d1471c054c4c45134f77;hp=f8d097e368aac39c8925f53016dd4012ffe349e1;hb=4ad490007b70e6ac18d3cb04fa2ed92eba1451fa;hpb=b3680f49e20c51e31c8dea84a11207df7b8f0100 diff --git a/src/core/manager.c b/src/core/manager.c index f8d097e36..6ba51a411 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -55,7 +55,6 @@ #include "util.h" #include "mkdir.h" #include "ratelimit.h" -#include "cgroup.h" #include "mount-setup.h" #include "unit-name.h" #include "dbus-unit.h" @@ -440,10 +439,9 @@ int manager_new(SystemdRunningAs running_as, Manager **_m) { if (!m) return -ENOMEM; - dual_timestamp_get(&m->userspace_timestamp); - dual_timestamp_from_monotonic(&m->kernel_timestamp, 0); #ifdef ENABLE_EFI - efi_get_boot_timestamps(&m->userspace_timestamp, &m->firmware_timestamp, &m->loader_timestamp); + if (detect_container(NULL) <= 0) + efi_get_boot_timestamps(&m->userspace_timestamp, &m->firmware_timestamp, &m->loader_timestamp); #endif m->running_as = running_as; @@ -468,12 +466,6 @@ int manager_new(SystemdRunningAs running_as, Manager **_m) { manager_strip_environment(m); - if (running_as == SYSTEMD_SYSTEM) { - m->default_controllers = strv_new("cpu", NULL); - if (!m->default_controllers) - goto fail; - } - if (!(m->units = hashmap_new(string_hash_func, string_compare_func))) goto fail; @@ -483,7 +475,8 @@ int manager_new(SystemdRunningAs running_as, Manager **_m) { if (!(m->watch_pids = hashmap_new(trivial_hash_func, trivial_compare_func))) goto fail; - if (!(m->cgroup_bondings = hashmap_new(string_hash_func, string_compare_func))) + m->cgroup_unit = hashmap_new(string_hash_func, string_compare_func); + if (!m->cgroup_unit) goto fail; if (!(m->watch_bus = hashmap_new(string_hash_func, string_compare_func))) @@ -510,9 +503,13 @@ int manager_new(SystemdRunningAs running_as, Manager **_m) { goto fail; /* Try to connect to the busses, if possible. */ - r = bus_init(m, running_as != SYSTEMD_SYSTEM); - if (r < 0) - goto fail; + if ((running_as == SYSTEMD_USER && getenv("DBUS_SESSION_BUS_ADDRESS")) || + running_as == SYSTEMD_SYSTEM) { + r = bus_init(m, running_as != SYSTEMD_SYSTEM); + if (r < 0) + goto fail; + } else + log_debug("Skipping DBus session bus connection attempt - no DBUS_SESSION_BUS_ADDRESS set..."); m->taint_usr = dir_is_empty("/usr") > 0; @@ -709,9 +706,7 @@ void manager_free(Manager *m) { lookup_paths_free(&m->lookup_paths); strv_free(m->environment); - strv_free(m->default_controllers); - - hashmap_free(m->cgroup_bondings); + hashmap_free(m->cgroup_unit); set_free_free(m->unit_path_cache); close_pipe(m->idle_pipe); @@ -766,7 +761,7 @@ int manager_coldplug(Manager *m) { static void manager_build_unit_path_cache(Manager *m) { char **i; - DIR _cleanup_free_ *d = NULL; + _cleanup_free_ DIR *d = NULL; int r; assert(m); @@ -804,11 +799,9 @@ static void manager_build_unit_path_cache(Manager *m) { goto fail; } - r = set_put(m->unit_path_cache, p); - if (r < 0) { - free(p); + r = set_consume(m->unit_path_cache, p); + if (r < 0) goto fail; - } } closedir(d); @@ -829,7 +822,9 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) { assert(m); + dual_timestamp_get(&m->generators_start_timestamp); manager_run_generators(m); + dual_timestamp_get(&m->generators_finish_timestamp); r = lookup_paths_init( &m->lookup_paths, m->running_as, true, @@ -848,7 +843,9 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) { m->n_reloading ++; /* First, enumerate what we can from all config files */ + dual_timestamp_get(&m->unitsload_start_timestamp); r = manager_enumerate(m); + dual_timestamp_get(&m->unitsload_finish_timestamp); /* Second, deserialize if there is something to deserialize */ if (serialization) { @@ -1040,7 +1037,8 @@ int manager_load_unit_prepare(Manager *m, const char *name, const char *path, DB } } - if ((r = unit_add_name(ret, name)) < 0) { + r = unit_add_name(ret, name); + if (r < 0) { unit_free(ret); return r; } @@ -1189,7 +1187,7 @@ static int manager_process_notify_fd(Manager *m) { }; struct ucred *ucred; Unit *u; - char _cleanup_strv_free_ **tags = NULL; + _cleanup_strv_free_ char **tags = NULL; n = recvmsg(m->notify_watch.fd, &msghdr, MSG_DONTWAIT); if (n <= 0) { @@ -1214,7 +1212,7 @@ static int manager_process_notify_fd(Manager *m) { u = hashmap_get(m->watch_pids, LONG_TO_PTR(ucred->pid)); if (!u) { - u = cgroup_unit_by_pid(m, ucred->pid); + u = manager_get_unit_by_pid(m, ucred->pid); if (!u) { log_warning("Cannot find unit for notify message of PID %lu.", (unsigned long) ucred->pid); continue; @@ -1262,7 +1260,7 @@ static int manager_dispatch_sigchld(Manager *m) { break; if (si.si_code == CLD_EXITED || si.si_code == CLD_KILLED || si.si_code == CLD_DUMPED) { - char _cleanup_free_ *name = NULL; + _cleanup_free_ char *name = NULL; get_process_comm(si.si_pid, &name); log_debug("Got SIGCHLD for process %lu (%s)", (unsigned long) si.si_pid, strna(name)); @@ -1279,7 +1277,7 @@ static int manager_dispatch_sigchld(Manager *m) { /* And now figure out the unit this belongs to */ u = hashmap_get(m->watch_pids, LONG_TO_PTR(si.si_pid)); if (!u) - u = cgroup_unit_by_pid(m, si.si_pid); + u = manager_get_unit_by_pid(m, si.si_pid); /* And now, we actually reap the zombie. */ if (waitid(P_PID, si.si_pid, &si, WEXITED) < 0) { @@ -1381,7 +1379,7 @@ static int manager_process_signal_fd(Manager *m) { case SIGINT: if (m->running_as == SYSTEMD_SYSTEM) { - manager_start_target(m, SPECIAL_CTRL_ALT_DEL_TARGET, JOB_REPLACE); + manager_start_target(m, SPECIAL_CTRL_ALT_DEL_TARGET, JOB_REPLACE_IRREVERSIBLY); break; } @@ -1735,6 +1733,9 @@ int manager_loop(Manager *m) { if (manager_dispatch_gc_queue(m) > 0) continue; + if (manager_dispatch_cgroup_queue(m) > 0) + continue; + if (manager_dispatch_dbus_queue(m) > 0) continue; @@ -2337,7 +2338,7 @@ void manager_reset_failed(Manager *m) { unit_reset_failed(u); } -bool manager_unit_pending_inactive(Manager *m, const char *name) { +bool manager_unit_inactive_or_pending(Manager *m, const char *name) { Unit *u; assert(m); @@ -2348,7 +2349,7 @@ bool manager_unit_pending_inactive(Manager *m, const char *name) { if (!u) return true; - return unit_pending_inactive(u); + return unit_inactive_or_pending(u); } void manager_check_finished(Manager *m) { @@ -2568,20 +2569,15 @@ void manager_undo_generators(Manager *m) { remove_generator_dir(m, &m->generator_unit_path_late); } -int manager_set_default_controllers(Manager *m, char **controllers) { - char **l; +int manager_set_default_environment(Manager *m, char **environment) { + char **e = NULL; assert(m); - - l = strv_copy(controllers); - if (!l) + e = strv_env_merge(2, m->environment, environment); + if (!e) return -ENOMEM; - - strv_free(m->default_controllers); - m->default_controllers = l; - - cg_shorten_controllers(m->default_controllers); - + strv_free(m->environment); + m->environment = e; return 0; }