Date: Sat, 6 Apr 1996 11:14:32 +0200 (MET DST) From: J Wunsch <j@uriah.heep.sax.de> To: freebsd-hackers@freebsd.org (FreeBSD hackers) Subject: Re: Any clues as to why this fails? Message-ID: <199604060914.LAA07471@uriah.heep.sax.de> In-Reply-To: <23387.828769307@time.cdrom.com> from "Jordan K. Hubbard" at Apr 5, 96 09:41:47 pm
index | next in thread | previous in thread | raw e-mail
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 <signal.h>
#include <fcntl.h>
#include <errno.h>
/* <<<<<<<<<<<<<<<<<<<< */
#include <sys/types.h>
#include <unistd.h>
#include <sys/ioctl.h>
/* >>>>>>>>>>>>>>>>>>>> */
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. ;-)
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199604060914.LAA07471>
