allow more criterions to be passed to exipick
authorMatthias Förste <foerste@schlittermann.de>
Thu, 17 Dec 2015 15:19:12 +0100
changeset 8 8aa513e99aaa
parent 7 97f19ea6d539
child 9 9978facb097a
allow more criterions to be passed to exipick
check_mailq.pl
--- a/check_mailq.pl	Thu Dec 17 13:51:53 2015 +0100
+++ b/check_mailq.pl	Thu Dec 17 15:19:12 2015 +0100
@@ -3,8 +3,11 @@
 # $URL$
 
 use strict;
+use warnings;
+
 use File::Basename;
 use Getopt::Long;
+use POSIX qw(:sys_wait_h);
 use lib "/usr/lib/nagios/plugins";
 use utils qw (%ERRORS &print_revision &support);
 
@@ -58,9 +61,20 @@
     exit $ERRORS{"CRITICAL"};
 }
 
+$SIG{CHLD} = sub {
+    while (waitpid(-1, WNOHANG) > 0) {};
+};
+
 # check the mailq
-`$opt_b -o $opt_s -c` =~ /^(\d+).*/;
-$mailq = $1;
+die "Can't fork: $!" unless defined (my $pid = open(F, "-|"));
+if ($pid) {
+    <F> =~ /^(\d+).*/;
+    $mailq = $1;
+    close F;
+} else {
+    exec $opt_b, '-o', $opt_s, '-c', @ARGV
+        or die "can't exec $opt_b: $!";
+}
 
 SWITCH: {
     $mailq < $opt_w  and $result = "OK",       last;