perlquestion
Plankton
<p>
Dear Wise Monks,
</p><p>
I have been playing around with reading a FIFO that was created like so:
<code>
$ sudo mkfifo /var/log/blackhole.pipe
</code>
Then I modified my /etc/syslog.conf ...
<code>
$ cat /etc/syslog.conf
...
# test logger script
local1.* |/var/log/blackhole.pipe
</code>
... then restart syslogd. I can test like by executing ...
<code>
$ logger -p local1.info "test test"
$ logger -p local1.info "test test"
$ logger -p local1.info "test test"
$ logger -p local1.info "test test2"
</code>
.. and ...
<code>
$ cat /var/log/blackhole.pipe
Oct 3 11:16:09 localhost plankton: test test
Oct 3 11:16:15 localhost last message repeated 2 times
Oct 3 11:16:19 localhost plankton: test test2
</code>
... but when I run this scripts ...
<code>
$ cat process_blackhole.pl
#!/usr/bin/perl -w
use strict;
$|=1;
my $fifo_file = "/var/log/blackhole.pipe";
my $fifo_fh;
open($fifo_fh, "+< $fifo_file") or die "The FIFO file \"$fifo_file\" is missing, and this program can't run without it.:$!";
# just keep reading from the fifo and processing the events we read
while (<$fifo_fh>) {
chomp;
print "read from pipe [$_]\n";
}
# should never really come down here ...
close $fifo_fh;
exit(0);
</code>
... I get this output ...
<code>
$ sudo ./process_blackhole.pl
read from pipe [Oct 3 11:22:45 localhost plankton: test test]
read from pipe [Oct 3 11:22:52 localhost plankton: test test2]
</code>
... The strange thing is I do not always get the <code>last message repeated 4 times</code> output consistently. Is there something else besides $|=1 and using the +< on my open call ?