From bb16b73130519cf5e93340480c8fd5e7e696a15f Mon Sep 17 00:00:00 2001 From: nafets Date: Mon, 17 Nov 2014 23:00:45 +0100 Subject: [PATCH 1/3] added option to exit with an warning, if there is output on STDERR --- plugins/check_by_ssh.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index a877f888f..bc172c975 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c @@ -49,6 +49,7 @@ unsigned int commands = 0; unsigned int services = 0; int skip_stdout = 0; int skip_stderr = 0; +int warn_on_stderr = 0; char *remotecmd = NULL; char **commargv = NULL; int commargc = 0; @@ -109,7 +110,10 @@ main (int argc, char **argv) if(chld_err.lines > skip_stderr) { printf (_("Remote command execution failed: %s\n"), chld_err.line[skip_stderr]); - return max_state_alt(result, STATE_UNKNOWN); + if ( warn_on_stderr ) + return max_state_alt(result, STATE_WARNING); + else + return max_state_alt(result, STATE_UNKNOWN); } /* this is simple if we're not supposed to be passive. @@ -182,6 +186,7 @@ process_arguments (int argc, char **argv) {"skip", optional_argument, 0, 'S'}, /* backwards compatibility */ {"skip-stdout", optional_argument, 0, 'S'}, {"skip-stderr", optional_argument, 0, 'E'}, + {"warn-on-stderr", no_argument, 0, 'W'}, {"proto1", no_argument, 0, '1'}, {"proto2", no_argument, 0, '2'}, {"use-ipv4", no_argument, 0, '4'}, @@ -301,6 +306,9 @@ process_arguments (int argc, char **argv) else skip_stderr = atoi (optarg); break; + case 'W': /* exit with warning if there is an output on stderr */ + warn_on_stderr = 1; + break; case 'o': /* Extra options for the ssh command */ comm_append("-o"); comm_append(optarg); @@ -408,6 +416,8 @@ print_help (void) printf (" %s\n", _("Ignore all or (if specified) first n lines on STDOUT [optional]")); printf (" %s\n", "-E, --skip-stderr[=n]"); printf (" %s\n", _("Ignore all or (if specified) first n lines on STDERR [optional]")); + printf (" %s\n", "-W, --warn-on-stderr]"); + printf (" %s\n", _("Exit with an warning, if there is an output on STDERR")); printf (" %s\n", "-f"); printf (" %s\n", _("tells ssh to fork rather than create a tty [optional]. This will always return OK if ssh is executed")); printf (" %s\n","-C, --command='COMMAND STRING'"); @@ -460,7 +470,7 @@ print_usage (void) { printf ("%s\n", _("Usage:")); printf (" %s -H -C [-fqv] [-1|-2] [-4|-6]\n" - " [-S [lines]] [-E [lines]] [-t timeout] [-i identity]\n" + " [-S [lines]] [-E [lines]] [-W] [-t timeout] [-i identity]\n" " [-l user] [-n name] [-s servicelist] [-O outputfile]\n" " [-p port] [-o ssh-option] [-F configfile]\n", progname); From 8639595e80efe905de532d144190e583132e636e Mon Sep 17 00:00:00 2001 From: nafets Date: Wed, 19 Nov 2014 18:56:11 +0100 Subject: [PATCH 2/3] avoid segfault, if ulimit is not set --- lib/utils_cmd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c index 9e214bd43..044aa5cb5 100644 --- a/lib/utils_cmd.c +++ b/lib/utils_cmd.c @@ -116,6 +116,14 @@ cmd_init (void) } #endif + /* if maxfd is unnaturally high, force it to a lower value + * ( e.g. on SunOS, when ulimit is set to unlimited: 2147483647 this would cause + * a segfault when following calloc is called ... ) */ + + if ( maxfd > 2048 ) { + maxfd = 2048; + } + if (!_cmd_pids) _cmd_pids = calloc (maxfd, sizeof (pid_t)); } From de84a2f50313807555d06601a43185588ab8b245 Mon Sep 17 00:00:00 2001 From: nafets Date: Wed, 19 Nov 2014 19:41:02 +0100 Subject: [PATCH 3/3] Revert "avoid segfault, if ulimit is not set", should be done in a branch This reverts commit 8639595e80efe905de532d144190e583132e636e. --- lib/utils_cmd.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c index 044aa5cb5..9e214bd43 100644 --- a/lib/utils_cmd.c +++ b/lib/utils_cmd.c @@ -116,14 +116,6 @@ cmd_init (void) } #endif - /* if maxfd is unnaturally high, force it to a lower value - * ( e.g. on SunOS, when ulimit is set to unlimited: 2147483647 this would cause - * a segfault when following calloc is called ... ) */ - - if ( maxfd > 2048 ) { - maxfd = 2048; - } - if (!_cmd_pids) _cmd_pids = calloc (maxfd, sizeof (pid_t)); }