[PATCH 1/1] setsid: should work for sub-threads
setsid() does not work unless the calling process is a
thread_group_leader().
'man setpgid' does not tell anything about that, so I consider
this behaviour is a bug.
Signed-off-by: Oren Laadan <[email protected]>
---
(see similar patch for setpgid by Oleg Nesterov). This one also required
modifying kernel/exit.c:__set_special_pids() (and it's prototype in
sched.h).
Please review...
diff --git a/include/linux/sched.h b/include/linux/sched.h
index b0ad6f3..9ff6e79 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1003,7 +1003,7 @@ extern struct mm_struct init_mm;
#define find_task_by_pid(nr) find_task_by_pid_type(PIDTYPE_PID, nr)
extern struct task_struct *find_task_by_pid_type(int type, int pid);
extern void set_special_pids(pid_t session, pid_t pgrp);
-extern void __set_special_pids(pid_t session, pid_t pgrp);
+extern void __set_special_pids(struct task_struct *tsk, pid_t session, pid_t pgrp);
/* per-UID process charging. */
extern struct user_struct * alloc_uid(uid_t);
diff --git a/kernel/exit.c b/kernel/exit.c
index ee51568..d47931f 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -256,26 +256,24 @@ static inline void reparent_to_init(void
switch_uid(INIT_USER);
}
-void __set_special_pids(pid_t session, pid_t pgrp)
+void __set_special_pids(struct task_struct *tsk, pid_t session, pid_t pgrp)
{
- struct task_struct *curr = current;
-
- if (curr->signal->session != session) {
- detach_pid(curr, PIDTYPE_SID);
- curr->signal->session = session;
- attach_pid(curr, PIDTYPE_SID, session);
- }
- if (process_group(curr) != pgrp) {
- detach_pid(curr, PIDTYPE_PGID);
- curr->signal->pgrp = pgrp;
- attach_pid(curr, PIDTYPE_PGID, pgrp);
+ if (tsk->signal->session != session) {
+ detach_pid(tsk, PIDTYPE_SID);
+ tsk->signal->session = session;
+ attach_pid(tsk, PIDTYPE_SID, session);
+ }
+ if (process_group(tsk) != pgrp) {
+ detach_pid(tsk, PIDTYPE_PGID);
+ tsk->signal->pgrp = pgrp;
+ attach_pid(tsk, PIDTYPE_PGID, pgrp);
}
}
void set_special_pids(pid_t session, pid_t pgrp)
{
write_lock_irq(&tasklist_lock);
- __set_special_pids(session, pgrp);
+ __set_special_pids(current, session, pgrp);
write_unlock_irq(&tasklist_lock);
}
diff --git a/kernel/sys.c b/kernel/sys.c
index bce933e..c907f88 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1207,24 +1207,22 @@ asmlinkage long sys_getsid(pid_t pid)
asmlinkage long sys_setsid(void)
{
+ struct task_struct *leader = current->group_leader;
struct pid *pid;
int err = -EPERM;
- if (!thread_group_leader(current))
- return -EINVAL;
-
down(&tty_sem);
write_lock_irq(&tasklist_lock);
- pid = find_pid(PIDTYPE_PGID, current->pid);
+ pid = find_pid(PIDTYPE_PGID, leader->pid);
if (pid)
goto out;
- current->signal->leader = 1;
- __set_special_pids(current->pid, current->pid);
- current->signal->tty = NULL;
- current->signal->tty_old_pgrp = 0;
- err = process_group(current);
+ leader->signal->leader = 1;
+ __set_special_pids(leader, leader->pid, leader->pid);
+ leader->signal->tty = NULL;
+ leader->signal->tty_old_pgrp = 0;
+ err = process_group(leader);
out:
write_unlock_irq(&tasklist_lock);
up(&tty_sem);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]