Messages in this thread |  | | Date | Sun, 14 Jul 1996 00:48:40 +0200 | From | Andries.Brouwer@cwi ... | Subject | Re: setsid() semantics changed... |
| |
Miquel van Smoorenburg:
: Today I noticed that setsid() didn't work anymore. This is due to : a change in 2.0.1. I know that around that time some patches went in : to let Linux comform more to POSIX, so that may be the cause. This : is what changed:
: diff -u --recursive --new-file v2.0.0/linux/kernel/sys.c linux/kernel/sys.c : --- v2.0.0/linux/kernel/sys.c Thu Jun 6 17:42:38 1996 : +++ linux/kernel/sys.c Tue Jul 2 19:08:43 1996 : @@ -634,8 +634,13 @@ : : asmlinkage int sys_setsid(void) : { : - if (current->leader) : - return -EPERM; : + struct task_struct * p; : + : + for_each_task(p) { : + if (p->pgrp == current->pid) : + return -EPERM; : + } : +
: Now a process that gets spawned by a shell that sets up the process group : for it (so it's the leader of it's own group, not session) cannot do : a setsid() anymore because the "if (p->pgrp == current->pid)" check will : match on itself.
: I now do a "setpgrp(0, getpgid(getppid()))" before setsid() and that works, : but I think the check should be
: if (p != current && p->pgrp == current->pid) : return -EPERM;
: But that could easily break POSIX conformance, I don't know...
You are quite right, and your version is POSIX conformant, not the kernel.
POSIX 4.3.2.4 reads:
EPERM The calling process is already a process group leader, or the process group ID of a process other than the calling process matches the process ID of the calling process.
Andries
|  |