Skip to contentSkip to conversation

sys_setpgid: eliminate unnecessary do_each_task_pid(PIDTYPE_PGID)

PATCH New Oleg Nesterov 1 participant 1 message Oct 23, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sys_setpgid: eliminate unnecessary do_each_task_pid(PIDTYPE_PGID)

On top of add-process_session-helper-routine.patch

All tasks in the process group have the same sid, we don't need to iterate them all to check that the caller of sys_setpgid() doesn't change its session.

kernel/sys.c renamed from kernel/sys.c~ +4 -7
@@ -1398,16 +1398,13 @@ asmlinkage long sys_setpgid(pid_t pid, p
 		goto out;
 
 	if (pgid != pid) {
-		struct task_struct *p;
+		struct task_struct *g =
+			find_task_by_pid_type(PIDTYPE_PGID, pgid);
 
-		do_each_task_pid(pgid, PIDTYPE_PGID, p) {
-			if (process_session(p) == process_session(group_leader))
-				goto ok_pgid;
-		} while_each_task_pid(pgid, PIDTYPE_PGID, p);
-		goto out;
+		if (!g || process_session(g) != process_session(group_leader))
+			goto out;
 	}
 
-ok_pgid:
 	err = security_task_setpgid(p, pgid);
 	if (err)
 		goto out;