tgummels has asked for the wisdom of the Perl Monks concerning the following question:
I'm attempting to watch two items with event, io and signal.
This should be simple but it isn't working the way I need it
to. If I start the script below and immediately send a sigterm
the signal isn't caught and the sub doesn't execute. My guess
is that the open is blocking for the first read on the pipe
to occur which is causing the signal to miss. The program
will catch the signal as long as the pipe has been read
at least once. Where am I going wrong? Any help will be
greatly appreciated.
TIA
Travis
CODE----
#!/usr/local/perl561/bin/perl
use IO::File;
use Event;
$FIFO = "npipe";
unless (-p $FIFO){
unlink $FIFO;
system ('/sbin/mknod', $FIFO,'p');
}
sub shutdown {
Event::unloop;
print "Good Bye!\n";
exit;
}
sub say_hello {
$fd = $_[0]->w->fd;
$fd->print("Hello\n");
$fd->close;
sysopen($fh,$FIFO,O_WRONLY);
}
$fh = new IO::File;
sysopen($fh,$FIFO,O_WRONLY);
Event->signal(signal=>'TERM',cb=>\&shutdown);
Event->io(fd=>$fh,cb=>\&say_hello, poll=>'w');
Event::loop;
|
|---|