Subject: setsid(2) bug
To: None <>
From: Christos Zoulas <>
List: current-users
Date: 02/24/1994 11:24:04
Setsid(2) does not void the controlling terminal association of the
current process.

% cat foo.c
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
main(argc, argv)
	int argc;
	char *argv[];
	if (open("/dev/tty", O_RDWR) != -1)
		printf("open worked!\n");
% cc foo.c
% a.out
open worked!

Here's the SunOS description:

       If  the calling process is not a process group leader, the
       setsid() function creates a new session.  The calling pro-
       cess  is  the session leader of this new session, the pro-
       cess group leader of a new process group, and has no  con-
       trolling  terminal.  If the process had a controlling ter-
       minal, setsid() breaks the association between the process
       and  that  controlling  terminal.  The process group ID of
       the calling process is set equal to the process ID of  the
       calling  process.  The calling process is the only process
       in the new process group and the only process in  the  new

I am not sure about the following patch, but I guess it should work
(I am compiling a kernel right now...)

*** kern_prot.c.orig	Sun Jan 23 05:38:17 1994
--- kern/kern_prot.c	Thu Feb 24 11:16:51 1994
*** 190,195 ****
--- 190,196 ----
  	if (p->p_pgid == p->p_pid || pgfind(p->p_pid)) {
  		return (EPERM);
  	} else {
+ 		p->p_flag &= ~SCTTY;
  		enterpgrp(p, p->p_pid, 1);
  		*retval = p->p_pid;
  		return (0);

For 4.4BSD SCTTY should be changed to P_CONTROLT.