Skip to contentSkip to conversation

cgroups: skip processes from other namespaces when listing a cgroup

PATCH In review gowrishankar 2 participants 2 messages Dec 8, 2008 – Dec 9, 2008 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cgroups: skip processes from other namespaces when listing a cgroup

Once tasks are populated from system namespace inside cgroup, container replaces other namespace task with 0 while listing tasks, inside container.

Though this is expected behaviour from container end, there is no use of showing unwanted 0s.

In below patch, we check if a process is in same namespace before loading into pid array.

---
 kernel/cgroup.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
kernel/cgroup.c +3 -2
index 35eebd5..25fdd2c 100644
@@ -2011,14 +2011,15 @@ int cgroup_scan_tasks(struct cgroup_scanner *scan)
  */
 static int pid_array_load(pid_t *pidarray, int npids, struct cgroup *cgrp)
 {
-    int n = 0;
+    int n = 0, pid;
     struct cgroup_iter it;
     struct task_struct *tsk;
     cgroup_iter_start(cgrp, &it);
     while ((tsk = cgroup_iter_next(cgrp, &it))) {
         if (unlikely(n == npids))
             break;
-        pidarray[n++] = task_pid_vnr(tsk);
+        if ((pid = task_pid_vnr(tsk)) > 0)
+            pidarray[n++] = pid;
     }
     cgroup_iter_end(cgrp, &it);
     return n;
Signature · 1 line
1.5.5.1

A message that is not in the archive (sent off-list or not yet received): 493CCB28.7000005-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org

#2 lore raw

kernel/cgroup.c int cgroup_scan_tasks(struct cgroup_scanner *scan) · line 2014

Quoted 10 lines · On Mon, 08 Dec 2008 12:52:16 +0530 gowrishankar…
kernel/cgroup.c +1 -1
index 35eebd5..25fdd2c 100644
@@ -2011,14 +2011,15 @@ int cgroup_scan_tasks(struct cgroup_scanner *scan)
  */
 static int pid_array_load(pid_t *pidarray, int npids, struct cgroup *cgrp)
 {
-    int n = 0;
+    int n = 0, pid;

Your email client is replacing tabs with spaces.

kernel/cgroup.c int cgroup_scan_tasks(struct cgroup_scanner *scan) · line 2022

Quoted 9 lines
kernel/cgroup.c +2 -1
     struct cgroup_iter it;
     struct task_struct *tsk;
     cgroup_iter_start(cgrp, &it);
     while ((tsk = cgroup_iter_next(cgrp, &it))) {
         if (unlikely(n == npids))
             break;
-        pidarray[n++] = task_pid_vnr(tsk);
+        if ((pid = task_pid_vnr(tsk)) > 0)
+            pidarray[n++] = pid;

Please avoid the assignment-in-an-if shorthand. We prefer to avoid tricky C idioms like this keep the code super-simple:

	pid = task_pid_vnr(tsk);
	if (pid > 0)

scripts/checkpatch.pl can/should be used to detect this, and many other little things.