From: jc@sppip7.lkg.dec.com (John Chambers)
Subject: Re: Does SIGIO work with FIFOs in Ultrix 4.2?
Date: 29 Apr 92 19:59:01 GMT [thread overview]
Message-ID: <1992Apr29.195901.10309@nntpd.lkg.dec.com> (raw)
In-Reply-To: 1992Apr28.143220.7221@nntpd.lkg.dec.com
We still haven't gotten SIGIO to work when there is data in a pipe,
but I do have a stripped-down version of the program that may or may
not hint what the problem is, while disproving all our hypotheses so
far. Our evidence so far is that Ultrix doesn't ever produce a SIGIO
signal when input arrives in a pipe. I'd love to be proved wrong...
To try the following program, you should "mknod tstpipe p" to create
its input pipe. You can then run it, and it will attempt to do
interrupt-driven input from the pipe. For input, I have a tiny little
program "jabber.c" that just does:
n = strlen(av[ac-1]);
while(1) {
write(1,av[ac-1],n); write(1,"\n",1); sleep(1);
}
and I direct stdout to tstpipe. This works fine, and "cat <tstpipe"
shows a message once per second like you'd expect.
The following "sigtst.c" program doesn't work fine. What it does is
open tstpipe for input, and tries to set it up so that when input is
available, sigIO() will be called. It then loops for 10 sec at a time,
and after each sleep(10), it tries to read from the pipe. You will
notice that the reads work, which is proof that data is flowing
through the pipe correctly. You will also notice that if you "kill
-23" the process, sigIO() gets called, proving that the kernel knows
about the SIGIO handler. But when the above jabbering program writes
to the pipe once a second, sigIO never gets called. Instead, every 10
seconds, the chunk() call reads 3 or 4 messages from the pipe and
outputs them, thus proving that the data was there although sigIO
wasn't called.
The weird thing is that sigIO() does get called if you kill the writer
to the pipe. This presumably does a close() on the write end, which
should produce an interrupt, and it does. The program then reads one
chunk and goes back to the sleep loop, hoping for another sigIO() call
which never comes (although there is usually more data in the pipe).
It appears that we now have proof that 1) The Ultrix 4.2 kernel knows
how to generate a SIGIO signal; 2) It generates this signal properly
when the writer exits; 3) It doesn't generate SIGIO when data is
written to the pipe.
BTW, someone (Matt Thomas upstairs, actually) suggested the F_SIGOWN
call. This doesn't fix the problem. But if you delete that line, then
the interrupts don't happen when the writer exits. This makes no sense
to me at all; fcntl(fil, F_SETOWN, pid) seems like a really demented
way to say "interrupt me if a writer to the pipe exits". I suspect
that it doesn't really mean this, but I haven't a clue as to what's
going on here. In fact, I don't have a clue as to why F_SETOWN should
even be necessary for this program to work.
Has anyone actually gotten a SIGIO signal to interrupt a program when
there is new data in a pipe? Can you show me a code fragment that does
it successfully? We have a strong suspicion that we might be the first
people to ever try it on this system.
Anyhow, here's the radically stripped-down program. I've tried various
orders to the signal() and fcntl() calls, to no avail. I also have a
debug version on hand with lots of failure messages, if that would
help any.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
/*
* This is a test program for the SIGIO signal. It opens a file and
* sets up asynchronous I/O on it, then sits in a loop waiting for
* interrupts. It does a read each time around the loop, to catch cases
* where the kernel fails to send the SIGIO interrupt. NOTE: This is a
* test program that DOES NOT WORK on Ultrix 4.2; I'm trying to find
* out why. DON'T use this as a prototype. IT DOESN'T WORK.
*/
#define BUF 64
char buf[BUF+1] = {0};
int bufsiz = BUF;
int fil = -1;
char *filnam = "tstpipe";
extern int errno;
extern void sigIO();
/*
* Read a buffer of data and display it.
*/
chunk()
{ int n;
n = read(fil, buf, bufsiz);
if (n > 0) {
buf[n] = 0;
fputs(buf, stdout); /* Dump to stdout */
fflush(stdout);
} else if (n == 0) {
errno = 0; /* This might be our exit status */
}
return n;
}
/*
* Input interrupt routine.
*/
void sigIO()
{
fputs("\nsigIO called.\n",stdout);
fflush(stdout);
chunk();
}
main(ac, av, ev)
char **av, **ev;
{ int a, n, s;
int pid;
for (a=1; a<ac; a++) {
switch (av[0][0]) {
default:
filnam = av[a];
} }
if ((fil = open(filnam, 0, 0)) < 0) {
exit(errno);
}
signal(SIGIO, sigIO); /* Declare IO interrupt handler */
fcntl(fil, F_SETFL, FASYNC); /* Ask for interrupts on this file */
pid = getpid();
fcntl(fil, F_SETOWN, pid); /* Matt Thomas suggested this */
while (1) {
sleep(10);
chunk(); /* Try to read some data */
}
/*NOTREACHED*/
}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
next parent reply other threads:[~1992-04-29 19:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1992Apr28.143220.7221@nntpd.lkg.dec.com>
1992-04-29 19:59 ` John Chambers [this message]
1992-05-04 20:19 ` Does SIGIO work with FIFOs in Ultrix 4.2? John Chambers
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox