* Re: Does SIGIO work with FIFOs in Ultrix 4.2?
[not found] <1992Apr28.143220.7221@nntpd.lkg.dec.com>
@ 1992-04-29 19:59 ` John Chambers
1992-05-04 20:19 ` John Chambers
0 siblings, 1 reply; 2+ messages in thread
From: John Chambers @ 1992-04-29 19:59 UTC (permalink / raw)
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*/
}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Does SIGIO work with FIFOs in Ultrix 4.2?
1992-04-29 19:59 ` Does SIGIO work with FIFOs in Ultrix 4.2? John Chambers
@ 1992-05-04 20:19 ` John Chambers
0 siblings, 0 replies; 2+ messages in thread
From: John Chambers @ 1992-05-04 20:19 UTC (permalink / raw)
Well, here I go yet again, following up my own message. I just thought
that maybe someone else might like to hear the resolution. Matt Thomas
(thomas@lkg.dec.com) verified that the problem is truly a kernel bug,
and that there is no apparent workaround. It seems that SIGIO simply
doesn't work (i.e., is not generated) when writing to a fifo on
Ultrix. The write routine doesn't send the signal. I checked on a 3.1
system that we happen to have lurking nearby, and it is just as broken
there as on our 4.1 and 4.2 systems.
The SIGIO signal is sent by the close code in the kernel, so it works
for things like scripts that echo messages one at a time to a fifo,
closing their output after each line. But for ordinary writes, there
is no way that a program can get an interrupt when there is new data.
SIGIO works just fine if a process sends it via kill(pid,SIGIO), but
this can only be done if both processes are on the same machine, and
the sender is either superuser of the same uid as the recipient (and
knows the pid of the recipient). In this case, of course, it is just
like any other signal.
I wonder if there are commercial systems out on which this actually
does work? It's documented in our POSIX manuals...
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1992-05-04 20:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1992Apr28.143220.7221@nntpd.lkg.dec.com>
1992-04-29 19:59 ` Does SIGIO work with FIFOs in Ultrix 4.2? John Chambers
1992-05-04 20:19 ` John Chambers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox