Kaynağa Gözat

check_snmp: add timeout handler befor running snmpget

Sven Nierlein 12 yıl önce
ebeveyn
işleme
4933146e00
1 değiştirilmiş dosya ile 10 ekleme ve 0 silme
  1. 10 0
      plugins/check_snmp.c

+ 10 - 0
plugins/check_snmp.c

@@ -33,6 +33,7 @@ const char *copyright = "1999-2007";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
 
 #include "common.h"
 #include "common.h"
+#include "runcmd.h"
 #include "utils.h"
 #include "utils.h"
 #include "utils_cmd.h"
 #include "utils_cmd.h"
 
 
@@ -330,9 +331,18 @@ main (int argc, char **argv)
 	if (verbose)
 	if (verbose)
 		printf ("%s\n", cl_hidden_auth);
 		printf ("%s\n", cl_hidden_auth);
 
 
+	/* Set signal handling and alarm */
+	if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) {
+		usage4 (_("Cannot catch SIGALRM"));
+	}
+	alarm(timeout_interval * retries + 5);
+
 	/* Run the command */
 	/* Run the command */
 	return_code = cmd_run_array (command_line, &chld_out, &chld_err, 0);
 	return_code = cmd_run_array (command_line, &chld_out, &chld_err, 0);
 
 
+	/* disable alarm again */
+	alarm(0);
+
 	/* Due to net-snmp sometimes showing stderr messages with poorly formed MIBs,
 	/* Due to net-snmp sometimes showing stderr messages with poorly formed MIBs,
 	   only return state unknown if return code is non zero or there is no stdout.
 	   only return state unknown if return code is non zero or there is no stdout.
 	   Do this way so that if there is stderr, will get added to output, which helps problem diagnosis
 	   Do this way so that if there is stderr, will get added to output, which helps problem diagnosis