summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2007-09-24 18:45:59 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2007-09-24 18:45:59 +0000
commit6625e6a0d2a4cec99339b8b526035592dcd4418c (patch)
tree85971687f4bfef6a7f30595522f2454c73f4b2af /lib
parent7fb5ed0f0a95ce5817e0b0f7c3bba91968393d49 (diff)
downloadmonitoring-plugin-perl-6625e6a0d2a4cec99339b8b526035592dcd4418c.tar.gz
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
Diffstat (limited to 'lib')
-rw-r--r--lib/Nagios/Plugin/Functions.pm26
-rw-r--r--lib/Nagios/Plugin/Getopt.pm4
2 files changed, 19 insertions, 11 deletions
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;
8use strict; 8use strict;
9use warnings; 9use warnings;
10use File::Basename; 10use File::Basename;
11use Params::Validate qw(validate :types); 11use Params::Validate qw(:types validate);
12use Math::Calc::Units; 12use Math::Calc::Units;
13 13
14# Remember to update Nagios::Plugins as well 14# Remember to update Nagios::Plugins as well
@@ -119,14 +119,24 @@ sub nagios_exit {
119 return Nagios::Plugin::ExitResult->new($code, $output); 119 return Nagios::Plugin::ExitResult->new($code, $output);
120 } 120 }
121 121
122 # Print output and exit; die if called via nagios_die and flag set 122 _nagios_exit($code, $output);
123 if($_use_die && (caller(1))[3] =~ m/die/) { 123}
124 $!=$code; 124
125 die($output); 125sub _nagios_exit {
126 } else { 126 my ($code, $output) = @_;
127 print $output; 127 # Print output and exit; die if flag set and called via a die in stack backtrace
128 exit $code; 128 if ($_use_die) {
129 for (my $i = 0;; $i++) {
130 @_ = caller($i);
131 last unless @_;
132 if ($_[3] =~ m/die/) {
133 $! = $code;
134 die($output);
135 }
136 }
129 } 137 }
138 print $output;
139 exit $code;
130} 140}
131 141
132# nagios_die( $message, [ $code ]) OR nagios_die( $code, $message ) 142# 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
60 my $self = shift; 60 my $self = shift;
61 my ($msg) = @_; 61 my ($msg) = @_;
62 $msg .= "\n" unless substr($msg, -1) eq "\n"; 62 $msg .= "\n" unless substr($msg, -1) eq "\n";
63 # Set errno to UNKNOWN for die return code 63 Nagios::Plugin::Functions::_nagios_exit(3, $msg);
64 local $! = 3;
65 die $msg;
66} 64}
67 65
68# Return the given attribute, if set, including a final newline 66# Return the given attribute, if set, including a final newline