chiark / gitweb /
core: add transient units
[elogind.git] / src / core / manager.c
index a7cfe570381ac5d9561497f671d7bf5d75298083..42c9bcd48cbf0d9a692a02e028c91d6aa82a4e9b 100644 (file)
@@ -55,7 +55,6 @@
 #include "util.h"
 #include "mkdir.h"
 #include "ratelimit.h"
 #include "util.h"
 #include "mkdir.h"
 #include "ratelimit.h"
-#include "cgroup.h"
 #include "mount-setup.h"
 #include "unit-name.h"
 #include "dbus-unit.h"
 #include "mount-setup.h"
 #include "unit-name.h"
 #include "dbus-unit.h"
@@ -467,12 +466,6 @@ int manager_new(SystemdRunningAs running_as, Manager **_m) {
 
         manager_strip_environment(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;
 
         if (!(m->units = hashmap_new(string_hash_func, string_compare_func)))
                 goto fail;
 
@@ -482,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->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)))
                 goto fail;
 
         if (!(m->watch_bus = hashmap_new(string_hash_func, string_compare_func)))
@@ -509,9 +503,13 @@ int manager_new(SystemdRunningAs running_as, Manager **_m) {
                 goto fail;
 
         /* Try to connect to the busses, if possible. */
                 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;
 
 
         m->taint_usr = dir_is_empty("/usr") > 0;
 
@@ -708,9 +706,7 @@ void manager_free(Manager *m) {
         lookup_paths_free(&m->lookup_paths);
         strv_free(m->environment);
 
         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);
         set_free_free(m->unit_path_cache);
 
         close_pipe(m->idle_pipe);
@@ -826,7 +822,9 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
 
         assert(m);
 
 
         assert(m);
 
+        dual_timestamp_get(&m->generators_start_timestamp);
         manager_run_generators(m);
         manager_run_generators(m);
+        dual_timestamp_get(&m->generators_finish_timestamp);
 
         r = lookup_paths_init(
                         &m->lookup_paths, m->running_as, true,
 
         r = lookup_paths_init(
                         &m->lookup_paths, m->running_as, true,
@@ -845,7 +843,9 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
                 m->n_reloading ++;
 
         /* First, enumerate what we can from all config files */
                 m->n_reloading ++;
 
         /* First, enumerate what we can from all config files */
+        dual_timestamp_get(&m->unitsload_start_timestamp);
         r = manager_enumerate(m);
         r = manager_enumerate(m);
+        dual_timestamp_get(&m->unitsload_finish_timestamp);
 
         /* Second, deserialize if there is something to deserialize */
         if (serialization) {
 
         /* Second, deserialize if there is something to deserialize */
         if (serialization) {
@@ -993,7 +993,13 @@ unsigned manager_dispatch_load_queue(Manager *m) {
         return n;
 }
 
         return n;
 }
 
-int manager_load_unit_prepare(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret) {
+int manager_load_unit_prepare(
+                Manager *m,
+                const char *name,
+                const char *path,
+                DBusError *e,
+                Unit **_ret) {
+
         Unit *ret;
         UnitType t;
         int r;
         Unit *ret;
         UnitType t;
         int r;
@@ -1037,7 +1043,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;
         }
                 unit_free(ret);
                 return r;
         }
@@ -1052,7 +1059,13 @@ int manager_load_unit_prepare(Manager *m, const char *name, const char *path, DB
         return 0;
 }
 
         return 0;
 }
 
-int manager_load_unit(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret) {
+int manager_load_unit(
+                Manager *m,
+                const char *name,
+                const char *path,
+                DBusError *e,
+                Unit **_ret) {
+
         int r;
 
         assert(m);
         int r;
 
         assert(m);
@@ -1211,7 +1224,7 @@ static int manager_process_notify_fd(Manager *m) {
 
                 u = hashmap_get(m->watch_pids, LONG_TO_PTR(ucred->pid));
                 if (!u) {
 
                 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;
                         if (!u) {
                                 log_warning("Cannot find unit for notify message of PID %lu.", (unsigned long) ucred->pid);
                                 continue;
@@ -1276,7 +1289,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)
                 /* 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) {
 
                 /* And now, we actually reap the zombie. */
                 if (waitid(P_PID, si.si_pid, &si, WEXITED) < 0) {
@@ -1732,6 +1745,9 @@ int manager_loop(Manager *m) {
                 if (manager_dispatch_gc_queue(m) > 0)
                         continue;
 
                 if (manager_dispatch_gc_queue(m) > 0)
                         continue;
 
+                if (manager_dispatch_cgroup_queue(m) > 0)
+                        continue;
+
                 if (manager_dispatch_dbus_queue(m) > 0)
                         continue;
 
                 if (manager_dispatch_dbus_queue(m) > 0)
                         continue;
 
@@ -2565,20 +2581,15 @@ void manager_undo_generators(Manager *m) {
         remove_generator_dir(m, &m->generator_unit_path_late);
 }
 
         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);
         assert(m);
-
-        l = strv_copy(controllers);
-        if (!l)
+        e = strv_env_merge(2, m->environment, environment);
+        if (!e)
                 return -ENOMEM;
                 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;
 }
 
         return 0;
 }