--- 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;