A bug in setpgid in kernel

H.J. Lu (hjl@lucon.org)
Sat, 14 Nov 1998 18:18:01 -0800 (PST)


Hi,

While working on the POSIX testsuite, I think I found another kernel
bug. This time it is setpgid. From The Single UNIX (R) Specification,
Version 2:

The setpgid() function is used either to join an existing process
group or create a new process group within the session of the calling
process. The process group ID of a session leader will not change.
Upon successful completion, the process group ID of the process with
a process ID that matches pid will be set to pgid. As a special case,
if pid is 0, the process ID of the calling process will be used. Also,
if pgid is 0, the process group ID of the indicated process will be used.

# gcc test1.c
# a.out 1
# a.out
Child abort failed
#

It looks like

setpgid((pid_t)0, (pid_t)0)

doesn't create a new process group.

BTW, the testcase works fine on Solaris 2.5.1 and HP-UX 10.20.

Thanks.

-- 
H.J. Lu (hjl@gnu.org)
---
#include <signal.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

#define WAITTIME 10

static void do_abort () { sleep (WAITTIME / 2); abort (); exit (0); }

static void do_stop () { pid_t pid = getpid();

if(kill(pid, SIGSTOP)) { perror ("kill"); exit (1); }

exit (0); }

static void child (int sel) { if (sel) { if(setpgid((pid_t)0, (pid_t)0) < 0) { perror ("setpgid"); exit (1); } } else { if(setsid () < 0) { perror ("setsid"); exit (1); } }

switch(fork()) { case -1: perror ("fork"); exit (1); break;

case 0: do_stop (); break;

default: break; } do_abort (); }

int main (int argc, char **argv) { int ret; int status; pid_t child_pid;

switch (child_pid = fork ()) { case 0: /* Child */ child (argc == 1); break;

case -1: perror ("fork"); exit (1); break;

default: break; }

ret = waitpid (child_pid, &status, WUNTRACED); if (ret < 0) { perror ("waitpid"); exit (1); } else { if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGABRT) { printf ("Child abort failed\n"); exit (3); } }

return 0; }

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/