From 6625e6a0d2a4cec99339b8b526035592dcd4418c Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Mon, 24 Sep 2007 18:45:59 +0000 Subject: Help, usage and version output go to stdout now, rather than stderr git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1795 f882894a-f735-0410-b71e-b25c423dba1c --- lib/Nagios/Plugin/Functions.pm | 26 ++++++++++++++++++-------- lib/Nagios/Plugin/Getopt.pm | 4 +--- 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm index e6baca9..87f0ccd 100644 --- a/lib/Nagios/Plugin/Functions.pm +++ b/lib/Nagios/Plugin/Functions.pm @@ -8,7 +8,7 @@ use 5.006; use strict; use warnings; use File::Basename; -use Params::Validate qw(validate :types); +use Params::Validate qw(:types validate); use Math::Calc::Units; # Remember to update Nagios::Plugins as well @@ -119,14 +119,24 @@ sub nagios_exit { return Nagios::Plugin::ExitResult->new($code, $output); } - # Print output and exit; die if called via nagios_die and flag set - if($_use_die && (caller(1))[3] =~ m/die/) { - $!=$code; - die($output); - } else { - print $output; - exit $code; + _nagios_exit($code, $output); +} + +sub _nagios_exit { + my ($code, $output) = @_; + # Print output and exit; die if flag set and called via a die in stack backtrace + if ($_use_die) { + for (my $i = 0;; $i++) { + @_ = caller($i); + last unless @_; + if ($_[3] =~ m/die/) { + $! = $code; + die($output); + } + } } + print $output; + exit $code; } # nagios_die( $message, [ $code ]) OR nagios_die( $code, $message ) diff --git a/lib/Nagios/Plugin/Getopt.pm b/lib/Nagios/Plugin/Getopt.pm index 743bf7e..b21dc6d 100644 --- a/lib/Nagios/Plugin/Getopt.pm +++ b/lib/Nagios/Plugin/Getopt.pm @@ -60,9 +60,7 @@ sub _die my $self = shift; my ($msg) = @_; $msg .= "\n" unless substr($msg, -1) eq "\n"; - # Set errno to UNKNOWN for die return code - local $! = 3; - die $msg; + Nagios::Plugin::Functions::_nagios_exit(3, $msg); } # Return the given attribute, if set, including a final newline -- cgit v1.2.3-74-g34f1