chiark / gitweb /
cgroup: never migrate kernel threads out of the root cgroup
[elogind.git] / src / basic / cgroup-util.c
index 4d321e30b3e30d30fa5ecc54f8ebeb74c945d96c..f96cd6339402e8182c32f00349dad11b2d704149 100644 (file)
@@ -321,6 +321,14 @@ int cg_migrate(const char *cfrom, const char *pfrom, const char *cto, const char
                         if (set_get(s, LONG_TO_PTR(pid)) == LONG_TO_PTR(pid))
                                 continue;
 
+                        /* Ignore kernel threads. Since they can only
+                         * exist in the root cgroup, we only check for
+                         * them there. */
+                        if (cfrom &&
+                            (isempty(pfrom) || path_equal(pfrom, "/")) &&
+                            is_kernel_thread(pid) > 0)
+                                continue;
+
                         r = cg_attach(cto, pto, pid);
                         if (r < 0) {
                                 if (ret >= 0 && r != -ESRCH)
@@ -615,6 +623,8 @@ int cg_create(const char *controller, const char *path) {
         return 1;
 }
 
+/// UNNEEDED by elogind
+#if 0
 int cg_create_and_attach(const char *controller, const char *path, pid_t pid) {
         int r, q;
 
@@ -631,6 +641,7 @@ int cg_create_and_attach(const char *controller, const char *path, pid_t pid) {
         /* This does not remove the cgroup on failure */
         return r;
 }
+#endif // 0
 
 int cg_attach(const char *controller, const char *path, pid_t pid) {
         _cleanup_free_ char *fs = NULL;
@@ -676,6 +687,8 @@ int cg_attach_fallback(const char *controller, const char *path, pid_t pid) {
         return 0;
 }
 
+/// UNNEEDED by elogind
+#if 0
 int cg_set_group_access(
                 const char *controller,
                 const char *path,
@@ -732,6 +745,7 @@ int cg_set_task_access(
 
         return chmod_and_chown(procs, mode, uid, gid);
 }
+#endif // 0
 
 int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
         _cleanup_fclose_ FILE *f = NULL;
@@ -806,6 +820,8 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
         return -ENOENT;
 }
 
+/// UNNEEDED by elogind
+#if 0
 int cg_install_release_agent(const char *controller, const char *agent) {
         _cleanup_free_ char *fs = NULL, *contents = NULL;
         char *sc;
@@ -829,14 +845,12 @@ int cg_install_release_agent(const char *controller, const char *agent) {
         } else if (!streq(sc, agent))
                 return -EEXIST;
 
-        free(fs);
-        fs = NULL;
+        fs = mfree(fs);
         r = cg_get_path(controller, NULL, "notify_on_release", &fs);
         if (r < 0)
                 return r;
 
-        free(contents);
-        contents = NULL;
+        contents = mfree(contents);
         r = read_one_line_file(fs, &contents);
         if (r < 0)
                 return r;
@@ -868,8 +882,7 @@ int cg_uninstall_release_agent(const char *controller) {
         if (r < 0)
                 return r;
 
-        free(fs);
-        fs = NULL;
+        fs = mfree(fs);
 
         r = cg_get_path(controller, NULL, "release_agent", &fs);
         if (r < 0)
@@ -881,6 +894,7 @@ int cg_uninstall_release_agent(const char *controller) {
 
         return 0;
 }
+#endif // 0
 
 int cg_is_empty(const char *controller, const char *path, bool ignore_self) {
         _cleanup_fclose_ FILE *f = NULL;
@@ -1351,8 +1365,6 @@ int cg_path_get_user_unit(const char *path, char **ret) {
         return cg_path_get_unit(t, ret);
 }
 
-/// UNNEDED by elogind
-#if 0
 int cg_pid_get_user_unit(pid_t pid, char **unit) {
         _cleanup_free_ char *cgroup = NULL;
         int r;
@@ -1365,7 +1377,6 @@ int cg_pid_get_user_unit(pid_t pid, char **unit) {
 
         return cg_path_get_user_unit(cgroup, unit);
 }
-#endif // 0
 
 int cg_path_get_machine_name(const char *path, char **machine) {
         _cleanup_free_ char *u = NULL, *sl = NULL;
@@ -1382,8 +1393,6 @@ int cg_path_get_machine_name(const char *path, char **machine) {
         return readlink_malloc(sl, machine);
 }
 
-/// UNNEDED by elogind
-#if 0
 int cg_pid_get_machine_name(pid_t pid, char **machine) {
         _cleanup_free_ char *cgroup = NULL;
         int r;
@@ -1396,7 +1405,6 @@ int cg_pid_get_machine_name(pid_t pid, char **machine) {
 
         return cg_path_get_machine_name(cgroup, machine);
 }
-#endif // 0
 
 int cg_path_get_session(const char *path, char **session) {
         _cleanup_free_ char *unit = NULL;
@@ -1469,8 +1477,6 @@ int cg_path_get_owner_uid(const char *path, uid_t *uid) {
         return 0;
 }
 
-/// UNNEDED by elogind
-#if 0
 int cg_pid_get_owner_uid(pid_t pid, uid_t *uid) {
         _cleanup_free_ char *cgroup = NULL;
         int r;
@@ -1481,7 +1487,6 @@ int cg_pid_get_owner_uid(pid_t pid, uid_t *uid) {
 
         return cg_path_get_owner_uid(cgroup, uid);
 }
-#endif // 0
 
 int cg_path_get_slice(const char *p, char **slice) {
         const char *e = NULL;
@@ -1713,7 +1718,6 @@ int cg_slice_to_path(const char *unit, char **ret) {
 
         return 0;
 }
-#endif // 0
 
 int cg_set_attribute(const char *controller, const char *path, const char *attribute, const char *value) {
         _cleanup_free_ char *p = NULL;
@@ -1736,6 +1740,7 @@ int cg_get_attribute(const char *controller, const char *path, const char *attri
 
         return read_one_line_file(p, ret);
 }
+#endif // 0
 
 static const char mask_names[] =
         "cpu\0"
@@ -1744,6 +1749,8 @@ static const char mask_names[] =
         "memory\0"
         "devices\0";
 
+/// UNNEEDED by elogind
+#if 0
 int cg_create_everywhere(CGroupControllerMask supported, CGroupControllerMask mask, const char *path) {
         CGroupControllerMask bit = 1;
         const char *n;
@@ -1770,6 +1777,7 @@ int cg_create_everywhere(CGroupControllerMask supported, CGroupControllerMask ma
 
         return 0;
 }
+#endif // 0
 
 int cg_attach_everywhere(CGroupControllerMask supported, const char *path, pid_t pid, cg_migrate_callback_t path_callback, void *userdata) {
         CGroupControllerMask bit = 1;
@@ -1800,6 +1808,8 @@ int cg_attach_everywhere(CGroupControllerMask supported, const char *path, pid_t
         return 0;
 }
 
+/// UNNEEDED by elogind
+#if 0
 int cg_attach_many_everywhere(CGroupControllerMask supported, const char *path, Set* pids, cg_migrate_callback_t path_callback, void *userdata) {
         Iterator i;
         void *pidp;
@@ -1930,3 +1940,4 @@ int cg_kernel_controllers(Set *controllers) {
 
         return 0;
 }
+#endif // 0