Parcourir la source

Made timeout_state and timeout_interval universal

I cannot find one instance where more than one of each of these globals
are needed:

timeout_state
timeout_interval

Previously, three seperate variables existed:

socket_timeout_state
timeout_state
runcmd_timeout_state

timeout_interval
socket_timeout
runcmd_timeout

I presume that at some point someone planned on using a few different
timeouts in a plugin.  As no plugin currently relies on this behavior as
far as I can tell, and as optarg will only let the user configure one
set, I decided to change all instances of these two vars to:

timeout_state
timeout_interval

This makes it easy to add just one parse_timeout_string function to
utils.c

I also noticed that runcmd.h did not include utils.h, but that all
plugins using runcmd.h also included utils.h.  I added utils.h to
runcmd's includes so that the global variables altered by the parse
function would be seen by the alarm handler in runcmd.c.

Let me know if anyone forsees any issues with these changes.

Still unresolved issues with timeout_intervals and check_snmp and a few
of the ntp plugins.
abrist il y a 11 ans
Parent
commit
8022f3c494

+ 1 - 1
plugins/check_apt.c

@@ -168,7 +168,7 @@ int process_arguments (int argc, char **argv) {
 			verbose++;
 			verbose++;
 			break;
 			break;
 		case 't':
 		case 't':
-			timeout_interval=parse_runcmd_timeout_string(optarg);
+			timeout_interval=parse_timeout_string(optarg);
 			break;
 			break;
 		case 'd':
 		case 'd':
 			upgrade=DIST_UPGRADE;
 			upgrade=DIST_UPGRADE;

+ 1 - 1
plugins/check_dig.c

@@ -260,7 +260,7 @@ process_arguments (int argc, char **argv)
       }
       }
       break;
       break;
     case 't':                 /* timeout */
     case 't':                 /* timeout */
-      timeout_interval = parse_runcmd_timeout_string (optarg);
+      timeout_interval = parse_timeout_string (optarg);
       break;
       break;
     case 'r':                 /* retires */
     case 'r':                 /* retires */
       if (is_intnonneg (optarg)) {
       if (is_intnonneg (optarg)) {

+ 4 - 4
plugins/check_http.c

@@ -173,7 +173,7 @@ main (int argc, char **argv)
 
 
   /* initialize alarm signal handling, set socket timeout, start timer */
   /* initialize alarm signal handling, set socket timeout, start timer */
   (void) signal (SIGALRM, socket_timeout_alarm_handler);
   (void) signal (SIGALRM, socket_timeout_alarm_handler);
-  (void) alarm (socket_timeout);
+  (void) alarm (timeout_interval);
   gettimeofday (&tv, NULL);
   gettimeofday (&tv, NULL);
 
 
   result = check_http ();
   result = check_http ();
@@ -274,7 +274,7 @@ process_arguments (int argc, char **argv)
       exit (STATE_OK);
       exit (STATE_OK);
       break;
       break;
     case 't': /* timeout period */
     case 't': /* timeout period */
-      socket_timeout = parse_socket_timeout_string(optarg);
+      timeout_interval = parse_timeout_string(optarg);
       break;
       break;
     case 'c': /* critical time threshold */
     case 'c': /* critical time threshold */
       critical_thresholds = optarg;
       critical_thresholds = optarg;
@@ -530,8 +530,8 @@ process_arguments (int argc, char **argv)
 
 
   set_thresholds(&thlds, warning_thresholds, critical_thresholds);
   set_thresholds(&thlds, warning_thresholds, critical_thresholds);
 
 
-  if (critical_thresholds && thlds->critical->end>(double)socket_timeout)
-    socket_timeout = (int)thlds->critical->end + 1;
+  if (critical_thresholds && thlds->critical->end>(double)timeout_interval)
+    timeout_interval = (int)thlds->critical->end + 1;
 
 
   if (http_method == NULL)
   if (http_method == NULL)
     http_method = strdup ("GET");
     http_method = strdup ("GET");

+ 2 - 2
plugins/check_ldap.c

@@ -115,7 +115,7 @@ main (int argc, char *argv[])
 	signal (SIGALRM, socket_timeout_alarm_handler);
 	signal (SIGALRM, socket_timeout_alarm_handler);
 
 
 	/* set socket timeout */
 	/* set socket timeout */
-	alarm (socket_timeout);
+	alarm (timeout_interval);
 
 
 	/* get the start time */
 	/* get the start time */
 	gettimeofday (&tv, NULL);
 	gettimeofday (&tv, NULL);
@@ -289,7 +289,7 @@ process_arguments (int argc, char **argv)
 			print_revision (progname, NP_VERSION);
 			print_revision (progname, NP_VERSION);
 			exit (STATE_OK);
 			exit (STATE_OK);
 		case 't':									/* timeout period */
 		case 't':									/* timeout period */
-			socket_timeout = parse_socket_timeout_string(optarg);
+			timeout_interval = parse_timeout_string(optarg);
 			break;
 			break;
 		case 'H':
 		case 'H':
 			ld_host = optarg;
 			ld_host = optarg;

+ 3 - 3
plugins/check_nt.c

@@ -130,7 +130,7 @@ int main(int argc, char **argv){
 	signal(SIGALRM,socket_timeout_alarm_handler);
 	signal(SIGALRM,socket_timeout_alarm_handler);
 
 
 	/* set socket timeout */
 	/* set socket timeout */
-	alarm(socket_timeout);
+	alarm(timeout_interval);
 
 
 	switch (vars_to_check) {
 	switch (vars_to_check) {
 
 
@@ -611,10 +611,10 @@ int process_arguments(int argc, char **argv){
 					show_all = TRUE;
 					show_all = TRUE;
 				break;
 				break;
 			case 'u':
 			case 'u':
-				socket_timeout_state=STATE_UNKNOWN;
+				timeout_state=STATE_UNKNOWN;
 				break;
 				break;
 			case 't': /* timeout */
 			case 't': /* timeout */
-				socket_timeout = parse_socket_timeout_string(optarg);
+				timeout_interval = parse_timeout_string(optarg);
 				break;
 				break;
 			}
 			}
 
 

+ 4 - 4
plugins/check_ntp.c

@@ -416,7 +416,7 @@ double offset_request(const char *host, int *status){
 	/* now do AVG_NUM checks to each host.  we stop before timeout/2 seconds
 	/* now do AVG_NUM checks to each host.  we stop before timeout/2 seconds
 	 * have passed in order to ensure post-processing and jitter time. */
 	 * have passed in order to ensure post-processing and jitter time. */
 	now_time=start_ts=time(NULL);
 	now_time=start_ts=time(NULL);
-	while(servers_completed<num_hosts && now_time-start_ts <= socket_timeout/2){
+	while(servers_completed<num_hosts && now_time-start_ts <= timeout_interval/2){
 		/* loop through each server and find each one which hasn't
 		/* loop through each server and find each one which hasn't
 		 * been touched in the past second or so and is still lacking
 		 * been touched in the past second or so and is still lacking
 		 * some responses.  for each of these servers, send a new request,
 		 * some responses.  for each of these servers, send a new request,
@@ -472,7 +472,7 @@ double offset_request(const char *host, int *status){
 	}
 	}
 
 
 	if (one_read == 0) {
 	if (one_read == 0) {
-		die(socket_timeout_state, "%s: No response from NTP server\n", state_text(socket_timeout_state));
+		die(timeout_state, "%s: No response from NTP server\n", state_text(timeout_state));
 	}
 	}
 
 
 	/* now, pick the best server from the list */
 	/* now, pick the best server from the list */
@@ -712,7 +712,7 @@ int process_arguments(int argc, char **argv){
 			server_address = strdup(optarg);
 			server_address = strdup(optarg);
 			break;
 			break;
 		case 't':
 		case 't':
-			socket_timeout = parse_socket_timeout_string(optarg);
+			timeout_interval = parse_timeout_string(optarg);
 			break;
 			break;
 		case '4':
 		case '4':
 			address_family = AF_INET;
 			address_family = AF_INET;
@@ -778,7 +778,7 @@ int main(int argc, char *argv[]){
 	signal (SIGALRM, socket_timeout_alarm_handler);
 	signal (SIGALRM, socket_timeout_alarm_handler);
 
 
 	/* set socket timeout */
 	/* set socket timeout */
-	alarm (socket_timeout);
+	alarm (timeout_interval);
 
 
 	offset = offset_request(server_address, &offset_result);
 	offset = offset_request(server_address, &offset_result);
 	/* check_ntp used to always return CRITICAL if offset_result == STATE_UNKNOWN.
 	/* check_ntp used to always return CRITICAL if offset_result == STATE_UNKNOWN.

+ 2 - 2
plugins/check_ntp_peer.c

@@ -501,7 +501,7 @@ int process_arguments(int argc, char **argv){
 			port=atoi(optarg);
 			port=atoi(optarg);
 			break;
 			break;
 		case 't':
 		case 't':
-			socket_timeout = parse_socket_timeout_string(optarg);
+			timeout_interval = parse_timeout_string(optarg);
 			break;
 			break;
 		case '4':
 		case '4':
 			address_family = AF_INET;
 			address_family = AF_INET;
@@ -583,7 +583,7 @@ int main(int argc, char *argv[]){
 	signal (SIGALRM, socket_timeout_alarm_handler);
 	signal (SIGALRM, socket_timeout_alarm_handler);
 
 
 	/* set socket timeout */
 	/* set socket timeout */
-	alarm (socket_timeout);
+	alarm (timeout_interval);
 
 
 	/* This returns either OK or WARNING (See comment preceeding ntp_request) */
 	/* This returns either OK or WARNING (See comment preceeding ntp_request) */
 	result = ntp_request(server_address, &offset, &offset_result, &jitter, &stratum, &num_truechimers);
 	result = ntp_request(server_address, &offset, &offset_result, &jitter, &stratum, &num_truechimers);

+ 4 - 4
plugins/check_ntp_time.c

@@ -362,7 +362,7 @@ double offset_request(const char *host, int *status){
 	/* now do AVG_NUM checks to each host. We stop before timeout/2 seconds
 	/* now do AVG_NUM checks to each host. We stop before timeout/2 seconds
 	 * have passed in order to ensure post-processing and jitter time. */
 	 * have passed in order to ensure post-processing and jitter time. */
 	now_time=start_ts=time(NULL);
 	now_time=start_ts=time(NULL);
-	while(servers_completed<num_hosts && now_time-start_ts <= socket_timeout/2){
+	while(servers_completed<num_hosts && now_time-start_ts <= timeout_interval/2){
 		/* loop through each server and find each one which hasn't
 		/* loop through each server and find each one which hasn't
 		 * been touched in the past second or so and is still lacking
 		 * been touched in the past second or so and is still lacking
 		 * some responses. For each of these servers, send a new request,
 		 * some responses. For each of these servers, send a new request,
@@ -418,7 +418,7 @@ double offset_request(const char *host, int *status){
 	}
 	}
 
 
 	if (one_read == 0) {
 	if (one_read == 0) {
-		die(socket_timeout_state, "%s: No response from NTP server\n", state_text(socket_timeout_state));
+		die(timeout_state, "%s: No response from NTP server\n", state_text(timeout_state));
 	}
 	}
 
 
 	/* now, pick the best server from the list */
 	/* now, pick the best server from the list */
@@ -503,7 +503,7 @@ int process_arguments(int argc, char **argv){
 			port = strdup(optarg);
 			port = strdup(optarg);
 			break;
 			break;
 		case 't':
 		case 't':
-			socket_timeout = parse_socket_timeout_string(optarg);
+			timeout_interval = parse_timeout_string(optarg);
 			break;
 			break;
 		case 'o':
 		case 'o':
 			time_offset=atoi(optarg);
 			time_offset=atoi(optarg);
@@ -563,7 +563,7 @@ int main(int argc, char *argv[]){
 	signal (SIGALRM, socket_timeout_alarm_handler);
 	signal (SIGALRM, socket_timeout_alarm_handler);
 
 
 	/* set socket timeout */
 	/* set socket timeout */
-	alarm (socket_timeout);
+	alarm (timeout_interval);
 
 
 	offset = offset_request(server_address, &offset_result);
 	offset = offset_request(server_address, &offset_result);
 	if (offset_result == STATE_UNKNOWN) {
 	if (offset_result == STATE_UNKNOWN) {

+ 2 - 2
plugins/check_nwstat.c

@@ -176,7 +176,7 @@ main(int argc, char **argv) {
 	signal(SIGALRM,socket_timeout_alarm_handler);
 	signal(SIGALRM,socket_timeout_alarm_handler);
 
 
 	/* set socket timeout */
 	/* set socket timeout */
-	alarm(socket_timeout);
+	alarm(timeout_interval);
 
 
 	/* open connection */
 	/* open connection */
 	my_tcp_connect (server_address, server_port, &sd);
 	my_tcp_connect (server_address, server_port, &sd);
@@ -1576,7 +1576,7 @@ int process_arguments(int argc, char **argv) {
 				check_critical_value=TRUE;
 				check_critical_value=TRUE;
 				break;
 				break;
 			case 't': /* timeout */
 			case 't': /* timeout */
-				socket_timeout = parse_socket_timeout_string(optarg);
+				timeout_interval = parse_timeout_string(optarg);
 			}
 			}
 
 
 	}
 	}

+ 2 - 2
plugins/check_overcr.c

@@ -105,7 +105,7 @@ main (int argc, char **argv)
 	signal (SIGALRM, socket_timeout_alarm_handler);
 	signal (SIGALRM, socket_timeout_alarm_handler);
 
 
 	/* set socket timeout */
 	/* set socket timeout */
-	alarm (socket_timeout);
+	alarm (timeout_interval);
 
 
 	result = process_tcp_request2 (server_address,
 	result = process_tcp_request2 (server_address,
 	                               server_port,
 	                               server_port,
@@ -395,7 +395,7 @@ process_arguments (int argc, char **argv)
 			check_critical_value = TRUE;
 			check_critical_value = TRUE;
 			break;
 			break;
 		case 't':									/* timeout */
 		case 't':									/* timeout */
-			socket_timeout = parse_socket_timeout_string (optarg);
+			timeout_interval = parse_timeout_string (optarg);
 		}
 		}
 
 
 	}
 	}

+ 2 - 2
plugins/check_real.c

@@ -83,7 +83,7 @@ main (int argc, char **argv)
 	signal (SIGALRM, socket_timeout_alarm_handler);
 	signal (SIGALRM, socket_timeout_alarm_handler);
 
 
 	/* set socket timeout */
 	/* set socket timeout */
-	alarm (socket_timeout);
+	alarm (timeout_interval);
 	time (&start_time);
 	time (&start_time);
 
 
 	/* try to connect to the host at the given port number */
 	/* try to connect to the host at the given port number */
@@ -349,7 +349,7 @@ process_arguments (int argc, char **argv)
 			verbose = TRUE;
 			verbose = TRUE;
 			break;
 			break;
 		case 't':									/* timeout */
 		case 't':									/* timeout */
-			socket_timeout = parse_socket_timeout_string (optarg);
+			timeout_interval = parse_timeout_string (optarg);
 			break;
 			break;
 		case 'V':									/* version */
 		case 'V':									/* version */
 			print_revision (progname, NP_VERSION);
 			print_revision (progname, NP_VERSION);

+ 2 - 2
plugins/check_smtp.c

@@ -173,7 +173,7 @@ main (int argc, char **argv)
 	(void) signal (SIGALRM, socket_timeout_alarm_handler);
 	(void) signal (SIGALRM, socket_timeout_alarm_handler);
 
 
 	/* set socket timeout */
 	/* set socket timeout */
-	(void) alarm (socket_timeout);
+	(void) alarm (timeout_interval);
 
 
 	/* start timer */
 	/* start timer */
 	gettimeofday (&tv, NULL);
 	gettimeofday (&tv, NULL);
@@ -574,7 +574,7 @@ process_arguments (int argc, char **argv)
 			ignore_send_quit_failure++;             /* ignore problem sending QUIT */
 			ignore_send_quit_failure++;             /* ignore problem sending QUIT */
 			break;
 			break;
 		case 't':									/* timeout */
 		case 't':									/* timeout */
-			socket_timeout = parse_socket_timeout_string (optarg);
+			timeout_interval = parse_timeout_string (optarg);
 			break;
 			break;
 		case 'S':
 		case 'S':
 		/* starttls */
 		/* starttls */

+ 3 - 3
plugins/check_snmp.c

@@ -353,11 +353,11 @@ main (int argc, char **argv)
 		external_error=1;
 		external_error=1;
 	if (external_error) {
 	if (external_error) {
 		if ((chld_err.lines > 0) && strstr(chld_err.line[0], "Timeout")) {
 		if ((chld_err.lines > 0) && strstr(chld_err.line[0], "Timeout")) {
-			printf (_("%s - External command error: %s\n"), state_text(runcmd_timeout_state), chld_err.line[0]);
+			printf (_("%s - External command error: %s\n"), state_text(timeout_state), chld_err.line[0]);
 			for (i = 1; i < chld_err.lines; i++) {
 			for (i = 1; i < chld_err.lines; i++) {
 				printf ("%s\n", chld_err.line[i]);
 				printf ("%s\n", chld_err.line[i]);
 			}
 			}
-			exit (runcmd_timeout_state);
+			exit (timeout_state);
 		} else if (chld_err.lines > 0) {
 		} else if (chld_err.lines > 0) {
 			printf (_("External command error: %s\n"), chld_err.line[0]);
 			printf (_("External command error: %s\n"), chld_err.line[0]);
 			for (i = 1; i < chld_err.lines; i++) {
 			for (i = 1; i < chld_err.lines; i++) {
@@ -762,7 +762,7 @@ process_arguments (int argc, char **argv)
 			privpasswd = optarg;
 			privpasswd = optarg;
 			break;
 			break;
 		case 't':	/* timeout period */
 		case 't':	/* timeout period */
-			timeout_interval = parse_runcmd_timeout_string (optarg);
+			timeout_interval = parse_timeout_string (optarg);
 			break;
 			break;
 	/* Test parameters */
 	/* Test parameters */
 		case 'c':									/* critical threshold */
 		case 'c':									/* critical threshold */

+ 3 - 3
plugins/check_ssh.c

@@ -76,7 +76,7 @@ main (int argc, char **argv)
 	/* initialize alarm signal handling */
 	/* initialize alarm signal handling */
 	signal (SIGALRM, socket_timeout_alarm_handler);
 	signal (SIGALRM, socket_timeout_alarm_handler);
 
 
-	alarm (socket_timeout);
+	alarm (timeout_interval);
 
 
 	/* ssh_connect exits if error is found */
 	/* ssh_connect exits if error is found */
 	result = ssh_connect (server_name, port, remote_version, remote_protocol);
 	result = ssh_connect (server_name, port, remote_version, remote_protocol);
@@ -136,7 +136,7 @@ process_arguments (int argc, char **argv)
 			verbose = TRUE;
 			verbose = TRUE;
 			break;
 			break;
 		case 't':									/* timeout period */
 		case 't':									/* timeout period */
-			socket_timeout = parse_socket_timeout_string (optarg);
+			timeout_interval = parse_timeout_string (optarg);
 			break;
 			break;
 		case '4':
 		case '4':
 			address_family = AF_INET;
 			address_family = AF_INET;
@@ -269,7 +269,7 @@ ssh_connect (char *haddr, int hport, char *remote_version, char *remote_protocol
 		printf
 		printf
 			(_("SSH OK - %s (protocol %s) | %s\n"),
 			(_("SSH OK - %s (protocol %s) | %s\n"),
 			 ssh_server, ssh_proto, fperfdata("time", elapsed_time, "s",
 			 ssh_server, ssh_proto, fperfdata("time", elapsed_time, "s",
-			 FALSE, 0, FALSE, 0, TRUE, 0, TRUE, (int)socket_timeout));
+			 FALSE, 0, FALSE, 0, TRUE, 0, TRUE, (int)timeout_interval));
 		close(sd);
 		close(sd);
 		exit (STATE_OK);
 		exit (STATE_OK);
 	}
 	}

+ 4 - 4
plugins/check_tcp.c

@@ -232,7 +232,7 @@ main (int argc, char **argv)
 
 
 	/* set up the timer */
 	/* set up the timer */
 	signal (SIGALRM, socket_timeout_alarm_handler);
 	signal (SIGALRM, socket_timeout_alarm_handler);
-	alarm (socket_timeout);
+	alarm (timeout_interval);
 
 
 	/* try to connect to the host at the given port number */
 	/* try to connect to the host at the given port number */
 	gettimeofday (&tv, NULL);
 	gettimeofday (&tv, NULL);
@@ -377,7 +377,7 @@ main (int argc, char **argv)
 				(flags & FLAG_TIME_WARN ? TRUE : FALSE), 0,
 				(flags & FLAG_TIME_WARN ? TRUE : FALSE), 0,
 				(flags & FLAG_TIME_CRIT ? TRUE : FALSE), 0,
 				(flags & FLAG_TIME_CRIT ? TRUE : FALSE), 0,
 				TRUE, 0,
 				TRUE, 0,
-				TRUE, socket_timeout)
+				TRUE, timeout_interval)
 			);
 			);
 	else
 	else
 		printf("|%s",
 		printf("|%s",
@@ -385,7 +385,7 @@ main (int argc, char **argv)
 				(flags & FLAG_TIME_WARN ? TRUE : FALSE), warning_time,
 				(flags & FLAG_TIME_WARN ? TRUE : FALSE), warning_time,
 				(flags & FLAG_TIME_CRIT ? TRUE : FALSE), critical_time,
 				(flags & FLAG_TIME_CRIT ? TRUE : FALSE), critical_time,
 				TRUE, 0,
 				TRUE, 0,
-				TRUE, socket_timeout)
+				TRUE, timeout_interval)
 			);
 			);
 
 
 	putchar('\n');
 	putchar('\n');
@@ -506,7 +506,7 @@ process_arguments (int argc, char **argv)
 			warn_codes[warn_codes_count - 1] = optarg;
 			warn_codes[warn_codes_count - 1] = optarg;
 			break;
 			break;
 		case 't':                 /* timeout */
 		case 't':                 /* timeout */
-			socket_timeout = parse_socket_timeout_string (optarg);
+			timeout_interval = parse_timeout_string (optarg);
 			break;
 			break;
 		case 'p':                 /* port */
 		case 'p':                 /* port */
 			if (!is_intpos (optarg))
 			if (!is_intpos (optarg))

+ 2 - 2
plugins/check_time.c

@@ -81,7 +81,7 @@ main (int argc, char **argv)
 	signal (SIGALRM, socket_timeout_alarm_handler);
 	signal (SIGALRM, socket_timeout_alarm_handler);
 
 
 	/* set socket timeout */
 	/* set socket timeout */
-	alarm (socket_timeout);
+	alarm (timeout_interval);
 	time (&start_time);
 	time (&start_time);
 
 
 	/* try to connect to the host at the given port number */
 	/* try to connect to the host at the given port number */
@@ -298,7 +298,7 @@ process_arguments (int argc, char **argv)
 				server_port = atoi (optarg);
 				server_port = atoi (optarg);
 			break;
 			break;
 		case 't':									/* timeout */
 		case 't':									/* timeout */
-			socket_timeout = parse_socket_timeout_string (optarg);
+			timeout_interval = parse_timeout_string (optarg);
 			break;
 			break;
 		case 'u':									/* udp */
 		case 'u':									/* udp */
 			use_udp = TRUE;
 			use_udp = TRUE;

+ 2 - 2
plugins/check_ups.c

@@ -125,7 +125,7 @@ main (int argc, char **argv)
 	signal (SIGALRM, socket_timeout_alarm_handler);
 	signal (SIGALRM, socket_timeout_alarm_handler);
 
 
 	/* set socket timeout */
 	/* set socket timeout */
-	alarm (socket_timeout);
+	alarm (timeout_interval);
 
 
 	/* get the ups status if possible */
 	/* get the ups status if possible */
 	if (determine_status () != OK)
 	if (determine_status () != OK)
@@ -549,7 +549,7 @@ process_arguments (int argc, char **argv)
 				usage2 (_("Unrecognized UPS variable"), optarg);
 				usage2 (_("Unrecognized UPS variable"), optarg);
 			break;
 			break;
 		case 't':									/* timeout */
 		case 't':									/* timeout */
-			socket_timeout = parse_socket_timeout_string (optarg);
+			timeout_interval = parse_timeout_string (optarg);
 			break;
 			break;
 		case 'V':									/* version */
 		case 'V':									/* version */
 			print_revision (progname, NP_VERSION);
 			print_revision (progname, NP_VERSION);

+ 1 - 4
plugins/negate.c

@@ -159,10 +159,7 @@ process_arguments (int argc, char **argv)
 			print_revision (progname, NP_VERSION);
 			print_revision (progname, NP_VERSION);
 			exit (EXIT_SUCCESS);
 			exit (EXIT_SUCCESS);
 		case 't':     /* timeout period */
 		case 't':     /* timeout period */
-			if (!is_integer (optarg))
-				usage2 (_("Timeout interval must be a positive integer"), optarg);
-			else
-				timeout_interval = atoi (optarg);
+			timeout_interval = parse_timeout_string (optarg);
 			break;
 			break;
 		case 'T':     /* Result to return on timeouts */
 		case 'T':     /* Result to return on timeouts */
 			if ((timeout_state = translate_state(optarg)) == ERROR)
 			if ((timeout_state = translate_state(optarg)) == ERROR)

+ 5 - 48
plugins/netutils.c

@@ -30,9 +30,6 @@
 #include "common.h"
 #include "common.h"
 #include "netutils.h"
 #include "netutils.h"
 
 
-unsigned int socket_timeout = DEFAULT_SOCKET_TIMEOUT;
-unsigned int socket_timeout_state = STATE_CRITICAL;
-
 int econn_refuse_state = STATE_CRITICAL;
 int econn_refuse_state = STATE_CRITICAL;
 int was_refused = FALSE;
 int was_refused = FALSE;
 #if USE_IPV6
 #if USE_IPV6
@@ -46,51 +43,11 @@ void
 socket_timeout_alarm_handler (int sig)
 socket_timeout_alarm_handler (int sig)
 {
 {
 	if (sig == SIGALRM)
 	if (sig == SIGALRM)
-		printf (_("%s - Socket timeout after %d seconds\n"), state_text(socket_timeout_state),  socket_timeout);
+		printf (_("%s - Socket timeout after %d seconds\n"), state_text(timeout_state),  timeout_interval);
 	else
 	else
-		printf (_("%s - Abnormal timeout after %d seconds\n"), state_text(socket_timeout_state), socket_timeout);
-
-	exit (socket_timeout_state);
-}
-
-void
-set_socket_timeout_state (char *state) {
-        if ((socket_timeout_state = translate_state(state)) == ERROR)
-                usage4 (_("Timeout result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
-}
+		printf (_("%s - Abnormal timeout after %d seconds\n"), state_text(timeout_state), timeout_interval);
 
 
-int
-parse_socket_timeout_string (char *timeout_str)
-{
-	char *seperated_str;
-        char *timeout_val = "";
-	char *timeout_sta;
-        if ( strstr(timeout_str, ":" ) == NULL) {
-		timeout_val = timeout_str;
-        } else if ( strncmp(timeout_str, ":", 1 ) == 0) {
-		seperated_str = strtok(timeout_str, ":");
-                if ( seperated_str != NULL ) {
-                	timeout_sta = seperated_str;
-		}
-        } else {
-		seperated_str = strtok(timeout_str, ":");
-                timeout_val = seperated_str;
-                seperated_str = strtok(NULL, ":");
-                if (seperated_str != NULL) {
-                        timeout_sta = seperated_str;
-                }
-        }
-        if ( timeout_sta != NULL ) {
-		set_socket_timeout_state(timeout_sta);
-	}
-	if (( timeout_val == NULL ) || ( timeout_val[0] == '\0' )) {
-		return socket_timeout;
-	} else if (is_intpos(timeout_val)) {
-		return atoi(timeout_val);
-	} else {
-		usage4 (_("Socket timeout value must be a positive integer"));
-		exit (STATE_UNKNOWN);
-	}
+	exit (timeout_state);
 }
 }
 
 
 /* connects to a host on a specified tcp port, sends a string, and gets a
 /* connects to a host on a specified tcp port, sends a string, and gets a
@@ -122,7 +79,7 @@ process_tcp_request2 (const char *server_address, int server_port,
 	while (1) {
 	while (1) {
 		/* wait up to the number of seconds for socket timeout
 		/* wait up to the number of seconds for socket timeout
 		   minus one for data from the host */
 		   minus one for data from the host */
-		tv.tv_sec = socket_timeout - 1;
+		tv.tv_sec = timeout_interval - 1;
 		tv.tv_usec = 0;
 		tv.tv_usec = 0;
 		FD_ZERO (&readfds);
 		FD_ZERO (&readfds);
 		FD_SET (sd, &readfds);
 		FD_SET (sd, &readfds);
@@ -323,7 +280,7 @@ send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int
 
 
 	/* wait up to the number of seconds for socket timeout minus one
 	/* wait up to the number of seconds for socket timeout minus one
 	   for data from the host */
 	   for data from the host */
-	tv.tv_sec = socket_timeout - 1;
+	tv.tv_sec = timeout_interval - 1;
 	tv.tv_usec = 0;
 	tv.tv_usec = 0;
 	FD_ZERO (&readfds);
 	FD_ZERO (&readfds);
 	FD_SET (sd, &readfds);
 	FD_SET (sd, &readfds);

+ 0 - 2
plugins/netutils.h

@@ -81,8 +81,6 @@ void host_or_die(const char *str);
 #  define is_hostname(addr) resolve_host_or_addr(addr, AF_INET)
 #  define is_hostname(addr) resolve_host_or_addr(addr, AF_INET)
 #endif
 #endif
 
 
-extern unsigned int socket_timeout;
-extern unsigned int socket_timeout_state;
 extern int econn_refuse_state;
 extern int econn_refuse_state;
 extern int was_refused;
 extern int was_refused;
 extern int address_family;
 extern int address_family;

+ 2 - 46
plugins/runcmd.c

@@ -67,9 +67,6 @@
  * occur in any number of threads simultaneously. */
  * occur in any number of threads simultaneously. */
 static pid_t *np_pids = NULL;
 static pid_t *np_pids = NULL;
 
 
-unsigned int runcmd_timeout_state = STATE_CRITICAL;
-unsigned int runcmd_timeout = DEFAULT_SOCKET_TIMEOUT;
-
 /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX.
 /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX.
  * If that fails and the macro isn't defined, we fall back to an educated
  * If that fails and the macro isn't defined, we fall back to an educated
  * guess. There's no guarantee that our guess is adequate and the program
  * guess. There's no guarantee that our guess is adequate and the program
@@ -264,54 +261,13 @@ runcmd_timeout_alarm_handler (int signo)
 	size_t i;
 	size_t i;
 
 
 	if (signo == SIGALRM)
 	if (signo == SIGALRM)
-		printf("%s - Plugin timed out while executing system call\n", state_text(runcmd_timeout_state));
+		printf("%s - Plugin timed out while executing system call\n", state_text(timeout_state));
 
 
 	if(np_pids) for(i = 0; i < maxfd; i++) {
 	if(np_pids) for(i = 0; i < maxfd; i++) {
 		if(np_pids[i] != 0) kill(np_pids[i], SIGKILL);
 		if(np_pids[i] != 0) kill(np_pids[i], SIGKILL);
 	}
 	}
 
 
-	exit (runcmd_timeout_state);
-}
-
-void
-set_runcmd_timeout_state (char *state)
-{
-        if ((runcmd_timeout_state = translate_state(state)) == ERROR)
-                usage4 (_("Timeout result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
-}
-
-int
-parse_runcmd_timeout_string (char *timeout_str)
-{
-	char *seperated_str;
-        char *timeout_val = "";
-	char *timeout_sta;
-        if ( strstr(timeout_str, ":" ) == NULL) {
-		timeout_val = timeout_str;
-        } else if ( strncmp(timeout_str, ":", 1 ) == 0) {
-		seperated_str = strtok(timeout_str, ":");
-                if ( seperated_str != NULL ) {
-                	timeout_sta = seperated_str;
-		}
-        } else {
-		seperated_str = strtok(timeout_str, ":");
-                timeout_val = seperated_str;
-                seperated_str = strtok(NULL, ":");
-                if (seperated_str != NULL) {
-                        timeout_sta = seperated_str;
-                }
-        }
-        if ( timeout_sta != NULL ) {
-		set_runcmd_timeout_state(timeout_sta);
-	}
-	if (( timeout_val == NULL ) || ( timeout_val[0] == '\0' )) {
-		return runcmd_timeout;
-	} else if (is_intpos(timeout_val)) {
-		return atoi(timeout_val);
-	} else {
-		usage4 (_("Socket timeout value must be a positive integer"));
-		exit (STATE_UNKNOWN);
-	}
+	exit (timeout_state);
 }
 }
 
 
 static int
 static int

+ 1 - 3
plugins/runcmd.h

@@ -26,9 +26,7 @@
 
 
 #include "common.h"
 #include "common.h"
 #include "utils_cmd.h" /* for the "output" type */
 #include "utils_cmd.h" /* for the "output" type */
-
-extern unsigned int runcmd_timeout_state;
-extern unsigned int runcmd_timeout;
+#include "utils.h"
 
 
 /** prototypes **/
 /** prototypes **/
 int np_runcmd(const char *, output *, output *, int);
 int np_runcmd(const char *, output *, output *, int);