summaryrefslogtreecommitdiff
path: root/include/linux/sched.h
diff options
context:
space:
mode:
authorAndrew Morton <akpm@osdl.org>2003-09-21 01:37:10 -0700
committerLinus Torvalds <torvalds@home.osdl.org>2003-09-21 01:37:10 -0700
commitfeaecce47220d2d8bf6f0d76e09dc623dbf991e0 (patch)
treebc7955b15df8dcdad59480fadc41c024c46e0231 /include/linux/sched.h
parent55b50278ec233024c2e5be04855d66ebdcebc35e (diff)
[PATCH] Fix setpgid and threads
From: Jeremy Fitzhardinge <jeremy@goop.org> I'm resending my patch to fix this problem. To recap: every task_struct has its own copy of the thread group's pgrp. Only the thread group leader is allowed to change the tgrp's pgrp, but it only updates its own copy of pgrp, while all the other threads in the tgrp use the old value they inherited on creation. This patch simply updates all the other thread's pgrp when the tgrp leader changes pgrp. Ulrich has already expressed reservations about this patch since it is (1) incomplete (it doesn't cover the case of other ids which have similar problems), (2) racy (it doesn't synchronize with other threads looking at the task pgrp, so they could see an inconsistent view) and (3) slow (it takes linear time with respect to the number of threads in the tgrp). My reaction is that (1) it fixes the actual bug I'm encountering in a real program. (2) doesn't really matter for pgrp, since it is mostly an issue with respect to the terminal job-control code (which is even more broken without this patch. Regarding (3), I think there are very few programs which have a large number of threads which change process group id on a regular basis (a heavily multi-threaded job-control shell?). Ulrich also said he has a (proposed?) much better fix, which I've been looking forward to. I'm submitting this patch as a stop-gap fix for a real bug, and perhaps to prompt the improved patch. An alternative fix, at least for pgrp, is to change all references to ->pgrp to group_leader->pgrp. This may be sufficient on its own, but it would be a reasonably intrusive patch (I count 95 instances in 32 files in the 2.6.0-test3-mm3 tree).
Diffstat (limited to 'include/linux/sched.h')
-rw-r--r--include/linux/sched.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 3d9aba07d508..9878dbef500a 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -362,7 +362,7 @@ struct task_struct {
unsigned long personality;
int did_exec:1;
pid_t pid;
- pid_t pgrp;
+ pid_t __pgrp; /* Accessed via process_group() */
pid_t tty_old_pgrp;
pid_t session;
pid_t tgid;
@@ -377,7 +377,7 @@ struct task_struct {
struct task_struct *parent; /* parent process */
struct list_head children; /* list of my children */
struct list_head sibling; /* linkage in my parent's children list */
- struct task_struct *group_leader;
+ struct task_struct *group_leader; /* threadgroup leader */
/* PID/PID hash table linkage. */
struct pid_link pids[PIDTYPE_MAX];
@@ -463,6 +463,11 @@ struct task_struct {
siginfo_t *last_siginfo; /* For ptrace use. */
};
+static inline pid_t process_group(struct task_struct *tsk)
+{
+ return tsk->group_leader->__pgrp;
+}
+
extern void __put_task_struct(struct task_struct *tsk);
#define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
#define put_task_struct(tsk) \