setsid() semantics changed...

Miquel van Smoorenburg (miquels@drinkel.cistron.nl)
13 Jul 1996 14:36:09 +0200


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...

Mike.

-- 
+ Miquel van Smoorenburg   + Cistron Internet Services +  Living is a     |
| miquels@cistron.nl (SP6) | Independent Dutch ISP     |   horizontal     |
+ miquels@drinkel.ow.org   + http://www.cistron.nl/    +      fall        +