chiark / gitweb /
Add --enable-debug=elogind configure option and fix cgroup path
[elogind.git] / src / core / cgroup.c
index 9b0339aae9e1050385e79f2b97b3468ae10c9d4f..139178ec075922e9387e428f901d9a69d12cac48 100644 (file)
@@ -24,7 +24,7 @@
 
 #include "process-util.h"
 #include "path-util.h"
-#include "special.h"
+// #include "special.h"
 #include "cgroup-util.h"
 #include "cgroup.h"
 
@@ -1232,7 +1232,8 @@ int manager_setup_cgroup(Manager *m) {
         r = cg_pid_get_path(ELOGIND_CGROUP_CONTROLLER, 0, &m->cgroup_root);
         if (r < 0)
                 return log_error_errno(r, "Cannot determine cgroup we are running in: %m");
-
+/// elogind does not support systemd scopes and slices
+#if 0
         /* Chop off the init scope, if we are already located in it */
         e = endswith(m->cgroup_root, "/" SPECIAL_INIT_SCOPE);
 
@@ -1247,12 +1248,15 @@ int manager_setup_cgroup(Manager *m) {
         }
         if (e)
                 *e = 0;
+#endif // 0
 
         /* And make sure to store away the root value without trailing
          * slash, even for the root dir, so that we can easily prepend
          * it everywhere. */
         while ((e = endswith(m->cgroup_root, "/")))
                 *e = 0;
+        log_debug_elogind("Cgroup Controller \"%s\" -> root \"%s\"",
+                          ELOGIND_CGROUP_CONTROLLER, m->cgroup_root);
 
         /* 2. Show data */
         r = cg_get_path(ELOGIND_CGROUP_CONTROLLER, m->cgroup_root, NULL, &path);
@@ -1313,17 +1317,31 @@ int manager_setup_cgroup(Manager *m) {
                                 log_debug("Release agent already installed.");
                 }
 
+/// elogind is not meant to run in systemd init scope
+#if 0
                 /* 4. Make sure we are in the special "init.scope" unit in the root slice. */
                 scope_path = strjoina(m->cgroup_root, "/" SPECIAL_INIT_SCOPE);
                 r = cg_create_and_attach(ELOGIND_CGROUP_CONTROLLER, scope_path, 0);
+#else
+                if (streq(m->cgroup_root, "/elogind"))
+                        // root already is our cgroup
+                        scope_path = strjoina(m->cgroup_root);
+                else
+                        // we have to create our own group
+                        scope_path = strjoina(m->cgroup_root, "/elogind");
+                r = cg_create_and_attach(ELOGIND_CGROUP_CONTROLLER, scope_path, 0);
+#endif // 0
                 if (r < 0)
                         return log_error_errno(r, "Failed to create %s control group: %m", scope_path);
+                log_debug_elogind("Created control group \"%s\"", scope_path);
 
                 /* also, move all other userspace processes remaining
                  * in the root cgroup into that scope. */
-                r = cg_migrate(ELOGIND_CGROUP_CONTROLLER, m->cgroup_root, ELOGIND_CGROUP_CONTROLLER, scope_path, false);
-                if (r < 0)
-                        log_warning_errno(r, "Couldn't move remaining userspace processes, ignoring: %m");
+                if (!streq(m->cgroup_root, scope_path)) {
+                        r = cg_migrate(ELOGIND_CGROUP_CONTROLLER, m->cgroup_root, ELOGIND_CGROUP_CONTROLLER, scope_path, false);
+                        if (r < 0)
+                                log_warning_errno(r, "Couldn't move remaining userspace processes, ignoring: %m");
+                }
 
                 /* 5. And pin it, so that it cannot be unmounted */
                 safe_close(m->pin_cgroupfs_fd);