Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 Nov 1996 02:51:00 +1100
From:      Bruce Evans <bde@zeta.org.au>
To:        hackers@FreeBSD.org, twpierce@midway.uchicago.edu
Subject:   Re: TIOCSPGRP on ptys?
Message-ID:  <199611081551.CAA08229@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>In 2.1.5, TIOCSPGRP ioctls cannot be made on slave
>pseudo-terminals.  In fact, the source for kern/tty_pty.c seems to
>be written to prevent *any* ioctls from being performed on slave
>ptys, and to prevent most TIOC ioctls from being performed on
>master ptys.
>
>Am I reading the source correctly?  This behavior seems to be
>inconsistent with the pty(4) man page:
>
>	The slave device provides to a process an in-
>	terface identical to that described in tty(4).
>
>If this is the intended behavior, what is the `correct'

Everything is as intended.  TIOCSPGRP only works on controlling
terminals, which is often not what is wanted.

>(i.e. portable, non-deprecated) method for setting the process
>group for a pty?  I see a TIOCSCTTY ioctl and a `login_tty'
>function in libutil, but no documentation, and am not sure whether
>these interfaces are stable or experimental.

There is no portable method.  In BSD4.4Lite, there is essentially only
one working method:

1. Stop being a process group leader, e.g., by forking and continuing
   in the child.  This is necessary for step 2 to work.  See setsid(2).
2. Open the new tty.
3. Call setsid() to become a session leader.
4. Call ioctl(fd, TIOCSCTTY) to get a controlling terminal.
5. Call tcsetpgrp(fd, groupid) or an ioctl to set the process group.

login_tty() does steps (3) and (4) plus some simple plumbing.  It is
documented in lgin_tty.c :-).  These interfaces have been stable for
4+ years.

Controlling terminals don't go away until the are completely closed and
the session leader exits.  Session leaders can change their controlling
terminal, but this is not much use for avoiding the fork in step (1) -
normally the session leader is a shell, and child processes neither can
nor want to change the main controlling terminal.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199611081551.CAA08229>