From owner-freebsd-hackers Wed Nov 13 00:22:06 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id AAA02301 for hackers-outgoing; Wed, 13 Nov 1996 00:22:06 -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 AAA02294 for ; Wed, 13 Nov 1996 00:21:55 -0800 (PST) Received: (from bde@localhost) by godzilla.zeta.org.au (8.7.6/8.6.9) id TAA28631; Wed, 13 Nov 1996 19:16:18 +1100 Date: Wed, 13 Nov 1996 19:16:18 +1100 From: Bruce Evans Message-Id: <199611130816.TAA28631@godzilla.zeta.org.au> To: hackers@freebsd.org, jkh@time.cdrom.com Subject: Re: Is our ASYNC I/O support for ttys broken? Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk >Thomas Roell over at X Inside just sent me this little snippet, >complaining that ASYNC I/O was broken in FreeBSD where it worked with >Linux and SVR4. Any comments? The status hasn't changed since he complained a year or so ago. SIGIO for ASYNC tty i/o is only sent to the process group of the tty, and process group stuff is limited by it being POSIX conformant with few extensions - the process group can not be changed using F_SETOWN (although F_SETOWN takes you outside of POSIX) unless the corresponding change using tcsetpgrp() would work. SIGIO for ASYNC socket i/o works better because the process or process group of the socket, and this is unrelated to the POSIX process group. > fd = open("/dev/ttyd0", O_RDONLY | O_NONBLOCK); > > fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | FASYNC); > fcntl(fd, F_SETOWN, getpid()); The second fcntl is guaranteed to fail, since `fd' isn't a controlling terminal. To make fd a controlling terminal, something like the following must be done: fork() wait in parent, continue as follows in child: setsid(); /* become a session leader with no ctty */ open as above first fcntl as above ioctl(fd, TIOCSCTTY, NULL); /* make fd the ctty */ second fcntl as above Bruce