[comp.unix.internals] TIOCNOTTY ioctl under Sys5

iain@estevax.UUCP (Hr Iain Lea) (04/03/91)

I am converting a piece of BSD code to Sys5 and would like
to know if there is a ioctl call that has the same function
as TIOCNOTTY ( void tty ) ?

Thanx

Iain

ehmeier@immd4.informatik.uni-erlangen.de (Erich Meier) (04/03/91)

iain@estevax.UUCP (Hr Iain Lea) writes:
>I am converting a piece of BSD code to Sys5 and would like
>to know if there is a ioctl call that has the same function
>as TIOCNOTTY ( void tty ) ?
In SysV there's a syscall setpgrp(2) or setsid(2), which
disconnects your process from its controlling tty.

Erich
---
Erich Meier          e-mail: ehmeier@medusa.informatik.uni-erlangen.de
	Obi-Wan-Kenobi: "Use the source...ah...force, Luke!"

dkeisen@Gang-of-Four.Stanford.EDU (Dave Eisen) (04/04/91)

In article <2177@estevax.UUCP> iain@estevax.UUCP (Hr Iain Lea) writes:
>I am converting a piece of BSD code to Sys5 and would like
>to know if there is a ioctl call that has the same function
>as TIOCNOTTY ( void tty ) ?
>

No there isn't. But there is a way of accomplishing the same thing
as this ioctl does, namely getting rid of the process group's control
terminal.

In BSD, one usually calls sepgrp to remove the process and its descendants 
from the process group of its parent and then one uses this ioctl
to make sure this process group doesn't have a control terminal. In
System V, the setpgrp does both --- it changes the process group id of the
process to match its pid and it disassociates the process from its
controlling terminal.

The only remaining problem is that the first time this process opens
a terminal device it will reacquire a control terminal, namely the
terminal it just opened. The way to make sure that it won't reacquire
a terminal is to fork, have the parent exit, and do all your work in
the child. If a process does not have a control terminal and if its
pid doesn't match its process group id (i.e., it isn't a process group
leader), it can't acquire a control terminal.

So replace the BSD code:

   int fd;

   setpgrp (0, getpid ());

   if ((fd = open ("/dev/tty", O_RDWR)) != -1) {
      ioctl (fd, TIOCNOTTY, (void *) NULL);
      close (fd);
   }


with the System V code:

   setpgrp ();

   switch (fork ()) {
   case -1: 
      /* handle error somehow */; 
      break;
   case 0 : 
      break;
   default: 
      exit (0);
   }


  
--
Dave Eisen                      
1101 San Antonio Rd. Suite 102    
Mountain View, CA 94043                   
(415) 967-5644                   dkeisen@Gang-of-Four.Stanford.EDU (for now)

rbj@uunet.UU.NET (Root Boy Jim) (04/04/91)

In article <2177@estevax.UUCP> iain@estevax.UUCP (Hr Iain Lea) writes:
?I am converting a piece of BSD code to Sys5 and would like
?to know if there is a ioctl call that has the same function
?as TIOCNOTTY ( void tty ) ?

I don't know the exact particulars, but look at setpgrp().
-- 
		[rbj@uunet 1] stty sane
		unknown mode: sane

lm@slovax.Eng.Sun.COM (Larry McVoy) (04/05/91)

In article <2177@estevax.UUCP>, iain@estevax.UUCP (Hr Iain Lea) writes:
|> I am converting a piece of BSD code to Sys5 and would like
|> to know if there is a ioctl call that has the same function
|> as TIOCNOTTY ( void tty ) ?

You probably want setsid(). 
---
Larry McVoy, Sun Microsystems     (415) 336-7627       ...!sun!lm or lm@sun.com