From owner-freebsd-hackers Sat Apr 6 01:59:07 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id BAA19706 for hackers-outgoing; Sat, 6 Apr 1996 01:59:07 -0800 (PST) Received: from irz301.inf.tu-dresden.de (irz301.inf.tu-dresden.de [141.76.1.11]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id BAA19680 for ; Sat, 6 Apr 1996 01:59:02 -0800 (PST) Received: from sax.sax.de by irz301.inf.tu-dresden.de (8.6.12/8.6.12-s1) with ESMTP id LAA10439 for ; Sat, 6 Apr 1996 11:58:59 +0200 Received: by sax.sax.de (8.6.11/8.6.12-s1) with UUCP id LAA17804 for freebsd-hackers@freebsd.org; Sat, 6 Apr 1996 11:58:58 +0200 Received: (from j@localhost) by uriah.heep.sax.de (8.7.4/8.6.9) id LAA07471 for freebsd-hackers@freebsd.org; Sat, 6 Apr 1996 11:14:34 +0200 (MET DST) From: J Wunsch Message-Id: <199604060914.LAA07471@uriah.heep.sax.de> Subject: Re: Any clues as to why this fails? To: freebsd-hackers@freebsd.org (FreeBSD hackers) Date: Sat, 6 Apr 1996 11:14:32 +0200 (MET DST) Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch) In-Reply-To: <23387.828769307@time.cdrom.com> from "Jordan K. Hubbard" at Apr 5, 96 09:41:47 pm X-Phone: +49-351-2012 669 X-Mailer: ELM [version 2.4 PL24 ME8a] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk As Jordan K. Hubbard wrote: > printf("%d\n", fcntl(fd, F_SETOWN, getpid())); /* This call returns -1 */ > I've read the man page for fcntl() and it really appears as though > that F_SETOWN call should work. Any clues as to why not? This Because the man page for fcntl() is incomplete and doesn't mention all possible error codes. F_SETOWN finally calls ioctl(TIOCSPGRP) on the descriptor, and this one (we should provide a source code license to Thomas short of having correct man pages :-) : case TIOCSPGRP: { /* set pgrp of tty */ register struct pgrp *pgrp = pgfind(*(int *)data); if (!isctty(p, tp)) return (ENOTTY); checks for the descriptor being a controlling tty. Apparently, this is not the case, unless you've been transferring the session to the tty in question before, and acquired the ctty. I don't know offhand what's the political^H^H^H^H^H^H^Hsixical correct way for the latter, but this one works (i've marked my changes): #include #include #include /* <<<<<<<<<<<<<<<<<<<< */ #include #include #include /* >>>>>>>>>>>>>>>>>>>> */ void handler(int sig) { printf("Signal %d received\n", sig); } main() { int i, fd; signal(SIGIO, handler); fd = open("/dev/cuaa1", O_RDONLY | O_NONBLOCK | O_EXCL); printf("%d\n", fd); i = fcntl(fd, F_GETFL, 0); printf("%d\n", i); /* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ if (fork()) exit(0); printf("%d\n", setsid()); printf("%d\n", ioctl(fd, TIOCSCTTY, NULL)); /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ printf("%d\n", fcntl(fd, F_SETFL, i | O_ASYNC)); printf("%d\n", fcntl(fd, F_SETOWN, getpid())); /* This call returns -1 */ pause(); } I don't know who in his right mind would really use SIGIO's these days. -- cheers, J"org joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE Never trust an operating system you don't have sources for. ;-)