From owner-freebsd-hackers Fri Nov 8 07:56:07 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id HAA16531 for hackers-outgoing; Fri, 8 Nov 1996 07:56:07 -0800 (PST) Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.19]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id HAA16472 for ; Fri, 8 Nov 1996 07:56:02 -0800 (PST) Received: (from bde@localhost) by godzilla.zeta.org.au (8.7.6/8.6.9) id CAA08229; Sat, 9 Nov 1996 02:51:00 +1100 Date: Sat, 9 Nov 1996 02:51:00 +1100 From: Bruce Evans Message-Id: <199611081551.CAA08229@godzilla.zeta.org.au> To: hackers@FreeBSD.org, twpierce@midway.uchicago.edu Subject: Re: TIOCSPGRP on ptys? Sender: owner-hackers@FreeBSD.org X-Loop: FreeBSD.org Precedence: bulk >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