#!/usr/bin/perl -w use constant FIFOPATH => "/tmp/fifo-demo"; use POSIX qw(mkfifo); use Fcntl qw(O_RDONLY); use Sys::Syslog qw( :DEFAULT setlogsock); # catch signals to die gracefully $SIG{'TERM'} = 'handler'; $SIG{'INT'} = 'handler'; # syslog sub do_syslog { my $msg = shift; setlogsock('unix'); openlog($0,'','user'); syslog('info',"$msg"); closelog; } sub handler { my $signal = shift; # signal-nummer besorgen $SIG{'TERM'} = 'handler'; # reinstall sig-handler $SIG{'INT'} = 'handler'; # reinstall sig-handler &do_syslog ("Signal: SIG$signal caught!"); unlink(FIFOPATH); exit 0; } sub do_notification { my $string = shift; &do_syslog($string); # instead of this 'sleep' here should be some intelligent code to # do magic stuff with the data we got from uncle fifo. sleep 5; } ########################### MAIN ################################ unlink(FIFOPATH); mkfifo(FIFOPATH, 0666) or die "can't create FIFO: $!\n"; sysopen(FIFOFD, FIFOPATH, O_RDONLY) or die "can't read: $!\n"; #my $fifostring = ""; #while (1) { # if (sysread(FIFOFD, $fromfifo, 1) == 1) { # if ($fromfifo eq "\n") { # &do_notification($fifostring); # $fifostring = ""; # } else { # $fifostring .= $fromfifo; # } # } #} # easyer reading line-by-line while (1) { while () { &do_notification($_); } }