diff options
Diffstat (limited to 'plugins/check_ping.c')
-rw-r--r-- | plugins/check_ping.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/plugins/check_ping.c b/plugins/check_ping.c index 26c0192..fd73b8c 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c | |||
@@ -55,7 +55,7 @@ int verbose = FALSE; | |||
55 | float rta = UNKNOWN_TRIP_TIME; | 55 | float rta = UNKNOWN_TRIP_TIME; |
56 | int pl = UNKNOWN_PACKET_LOSS; | 56 | int pl = UNKNOWN_PACKET_LOSS; |
57 | 57 | ||
58 | char *warn_text = ""; | 58 | char *warn_text; |
59 | 59 | ||
60 | 60 | ||
61 | 61 | ||
@@ -69,11 +69,10 @@ main (int argc, char **argv) | |||
69 | int this_result = STATE_UNKNOWN; | 69 | int this_result = STATE_UNKNOWN; |
70 | int i; | 70 | int i; |
71 | 71 | ||
72 | addresses = malloc (max_addr); | 72 | addresses = malloc ((size_t)max_addr); |
73 | 73 | ||
74 | if (process_arguments (argc, argv) == ERROR) | 74 | if (process_arguments (argc, argv) == ERROR) |
75 | usage (_("Could not parse arguments")); | 75 | usage (_("Could not parse arguments")); |
76 | exit; | ||
77 | 76 | ||
78 | /* Set signal handling and alarm */ | 77 | /* Set signal handling and alarm */ |
79 | if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { | 78 | if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { |
@@ -113,7 +112,7 @@ main (int argc, char **argv) | |||
113 | /* run the command */ | 112 | /* run the command */ |
114 | this_result = run_ping (cmd, addresses[i]); | 113 | this_result = run_ping (cmd, addresses[i]); |
115 | 114 | ||
116 | if (pl == UNKNOWN_PACKET_LOSS || rta == UNKNOWN_TRIP_TIME) { | 115 | if (pl == UNKNOWN_PACKET_LOSS || rta < 0.0) { |
117 | printf ("%s\n", cmd); | 116 | printf ("%s\n", cmd); |
118 | die (STATE_UNKNOWN, | 117 | die (STATE_UNKNOWN, |
119 | _("Error: Could not interpret output from ping command\n")); | 118 | _("Error: Could not interpret output from ping command\n")); |
@@ -193,12 +192,15 @@ process_arguments (int argc, char **argv) | |||
193 | switch (c) { | 192 | switch (c) { |
194 | case '?': /* usage */ | 193 | case '?': /* usage */ |
195 | usage3 (_("Unknown argument"), optopt); | 194 | usage3 (_("Unknown argument"), optopt); |
195 | break; | ||
196 | case 'h': /* help */ | 196 | case 'h': /* help */ |
197 | print_help (); | 197 | print_help (); |
198 | exit (STATE_OK); | 198 | exit (STATE_OK); |
199 | break; | ||
199 | case 'V': /* version */ | 200 | case 'V': /* version */ |
200 | print_revision (progname, revision); | 201 | print_revision (progname, revision); |
201 | exit (STATE_OK); | 202 | exit (STATE_OK); |
203 | break; | ||
202 | case 't': /* timeout period */ | 204 | case 't': /* timeout period */ |
203 | timeout_interval = atoi (optarg); | 205 | timeout_interval = atoi (optarg); |
204 | break; | 206 | break; |
@@ -221,7 +223,7 @@ process_arguments (int argc, char **argv) | |||
221 | n_addresses++; | 223 | n_addresses++; |
222 | if (n_addresses > max_addr) { | 224 | if (n_addresses > max_addr) { |
223 | max_addr *= 2; | 225 | max_addr *= 2; |
224 | addresses = realloc (addresses, max_addr); | 226 | addresses = realloc (addresses, (size_t)max_addr); |
225 | if (addresses == NULL) | 227 | if (addresses == NULL) |
226 | die (STATE_UNKNOWN, _("Could not realloc() addresses\n")); | 228 | die (STATE_UNKNOWN, _("Could not realloc() addresses\n")); |
227 | } | 229 | } |
@@ -292,7 +294,7 @@ process_arguments (int argc, char **argv) | |||
292 | } | 294 | } |
293 | } | 295 | } |
294 | 296 | ||
295 | if (wrta == UNKNOWN_TRIP_TIME) { | 297 | if (wrta < 0.0) { |
296 | if (is_negative (argv[c])) { | 298 | if (is_negative (argv[c])) { |
297 | printf (_("<wrta> (%s) must be a non-negative number\n"), argv[c]); | 299 | printf (_("<wrta> (%s) must be a non-negative number\n"), argv[c]); |
298 | return ERROR; | 300 | return ERROR; |
@@ -303,7 +305,7 @@ process_arguments (int argc, char **argv) | |||
303 | } | 305 | } |
304 | } | 306 | } |
305 | 307 | ||
306 | if (crta == UNKNOWN_TRIP_TIME) { | 308 | if (crta < 0.0) { |
307 | if (is_negative (argv[c])) { | 309 | if (is_negative (argv[c])) { |
308 | printf (_("<crta> (%s) must be a non-negative number\n"), argv[c]); | 310 | printf (_("<crta> (%s) must be a non-negative number\n"), argv[c]); |
309 | return ERROR; | 311 | return ERROR; |
@@ -346,11 +348,11 @@ validate_arguments () | |||
346 | float max_seconds; | 348 | float max_seconds; |
347 | int i; | 349 | int i; |
348 | 350 | ||
349 | if (wrta == UNKNOWN_TRIP_TIME) { | 351 | if (wrta < 0.0) { |
350 | printf (_("<wrta> was not set\n")); | 352 | printf (_("<wrta> was not set\n")); |
351 | return ERROR; | 353 | return ERROR; |
352 | } | 354 | } |
353 | else if (crta == UNKNOWN_TRIP_TIME) { | 355 | else if (crta < 0.0) { |
354 | printf (_("<crta> was not set\n")); | 356 | printf (_("<crta> was not set\n")); |
355 | return ERROR; | 357 | return ERROR; |
356 | } | 358 | } |
@@ -397,10 +399,9 @@ run_ping (char *cmd, char *server_address) | |||
397 | char buf[MAX_INPUT_BUFFER]; | 399 | char buf[MAX_INPUT_BUFFER]; |
398 | int result = STATE_UNKNOWN; | 400 | int result = STATE_UNKNOWN; |
399 | 401 | ||
400 | if ((child_process = spopen (cmd)) == NULL) { | 402 | if ((child_process = spopen (cmd)) == NULL) |
401 | printf (_("Cannot open pipe: ")); | 403 | die (STATE_UNKNOWN, _("Cannot open pipe: %s"), cmd); |
402 | die (STATE_UNKNOWN, cmd); | 404 | |
403 | } | ||
404 | child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); | 405 | child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); |
405 | if (child_stderr == NULL) | 406 | if (child_stderr == NULL) |
406 | printf (_("Cannot open stderr for %s\n"), cmd); | 407 | printf (_("Cannot open stderr for %s\n"), cmd); |
@@ -455,7 +456,7 @@ run_ping (char *cmd, char *server_address) | |||
455 | _("PING CRITICAL - Host not found (%s)"), | 456 | _("PING CRITICAL - Host not found (%s)"), |
456 | server_address); | 457 | server_address); |
457 | 458 | ||
458 | if (strlen (warn_text) == 0) | 459 | if (warn_text == NULL) |
459 | warn_text = strdup (buf); | 460 | warn_text = strdup (buf); |
460 | else if (asprintf (&warn_text, "%s %s", warn_text, buf) == -1) | 461 | else if (asprintf (&warn_text, "%s %s", warn_text, buf) == -1) |
461 | die (STATE_UNKNOWN, _("unable to realloc warn_text")); | 462 | die (STATE_UNKNOWN, _("unable to realloc warn_text")); |
@@ -472,6 +473,9 @@ run_ping (char *cmd, char *server_address) | |||
472 | if (spclose (child_process)) | 473 | if (spclose (child_process)) |
473 | result = max_state (result, STATE_WARNING); | 474 | result = max_state (result, STATE_WARNING); |
474 | 475 | ||
476 | if (warn_text == NULL) | ||
477 | warn_text = strdup(""); | ||
478 | |||
475 | return result; | 479 | return result; |
476 | } | 480 | } |
477 | 481 | ||