Listing 1. Reading Firewall Messages with kmsgsd

open LOG, ">> /var/log/psad/fwdata" or die
"$!\n";
while (1) {
   open FIFO, "< /var/log/psadfifo" or die "$!\n";
   $service = <FIFO>; # don't slow down with chomp
   if (($service =~ /Packet\slog/ || $service =~
/IN.+?OUT.+?MAC/) && $service =~
/DROP|REJECT|DENY/) {
      # log the denied/rejected packet to the
      # fwdata file
      my $old_fh = select LOG;
      $| = 1;  # take care of buffered output to LOG
      print "$service";
      select $old_fh;
   }
}