Originally posted by: SystemAdmin
thanks for the response.
We already tried what you mentioned, the first several messages can be redirected to the fifo(we can use tail to see this), but when we tried to use "open" to open the pipe, it will fail. We think the reason is that the syslog actually treat the fifo as a regular file, because we did not add any special flag to let the syslog know that it is a fifo, the syslog will open the fifo as "append" mode, so the other process can not open the fifo anymore...
Please correct me if I am wrong.
Here are the steps I am using:
mknod /tmp/syslog_fifo p
add "*.info /tmp/syslog_fifo"
refresh -s syslogd
logger -p crit "this is a test"
run the script readfifo I wrote:
#!/usr/bin/perl
while (1)
{
my $fifo = "/tmp/syslog_fifo";
local $SIG{ALRM} = sub { die "alarm\n" };
eval {
alarm 4;
open(PIPE, $fifo) or die
alarm 0;
};
if ($@ =~ /alarm/) { close PIPE; print "open pipe failed\n"; exit 0; }
while (1)
{
my $line;
eval {
alarm 2;
$line = <PIPE>;
alarm 0;
};
if ($@ =~ /alarm/) { close PIPE; last; }
chomp($line);
if ($line eq "") {close PIPE; last;}
print "String=\"$line\"\n";
}
close PIPE;
}
I will always get the error "open pipe failed".