diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-08-09 06:01:03 +0000 |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-08-09 06:01:03 +0000 |
commit | a228492c4bea15a3e6e7bdbfd6631611c97fe92c (patch) | |
tree | 0d21d5c54a2ab5ec3f4171fab668d390ea09bbaa | |
parent | 024751bac56791b7ae5347404274046e8ba58ccb (diff) | |
download | monitoring-plugins-a228492c4bea15a3e6e7bdbfd6631611c97fe92c.tar.gz |
more pedantic compiler warns
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@672 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r-- | plugins/check_dig.c | 4 | ||||
-rw-r--r-- | plugins/check_http.c | 1 | ||||
-rw-r--r-- | plugins/check_load.c | 6 | ||||
-rw-r--r-- | plugins/check_mrtg.c | 165 | ||||
-rw-r--r-- | plugins/check_mrtgtraf.c | 119 | ||||
-rw-r--r-- | plugins/check_nwstat.c | 33 | ||||
-rw-r--r-- | plugins/check_overcr.c | 26 | ||||
-rw-r--r-- | plugins/check_ping.c | 32 | ||||
-rw-r--r-- | plugins/check_procs.c | 109 | ||||
-rw-r--r-- | plugins/check_real.c | 31 | ||||
-rw-r--r-- | plugins/utils.c | 6 | ||||
-rw-r--r-- | plugins/utils.h | 6 |
12 files changed, 301 insertions, 237 deletions
diff --git a/plugins/check_dig.c b/plugins/check_dig.c index 7c39a243..ff160591 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c @@ -97,7 +97,7 @@ main (int argc, char **argv) input_buffer[strcspn (input_buffer, "\r\n")] = '\0'; if (strstr (input_buffer, query_address) == input_buffer) { - asprintf (&output, input_buffer); + output = strdup(input_buffer); result = STATE_OK; } else { @@ -119,7 +119,7 @@ main (int argc, char **argv) result = max_state (result, STATE_WARNING); printf ("%s", input_buffer); if (strlen (output) == 0) - asprintf (&output, 1 + index (input_buffer, ':')); + output = strdup (1 + index (input_buffer, ':')); } (void) fclose (child_stderr); diff --git a/plugins/check_http.c b/plugins/check_http.c index e2047edd..3321d5ac 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -992,6 +992,7 @@ print_help (void) { print_revision (progname, revision); + printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n")); printf (_(COPYRIGHT), copyright, email); printf (_("\ diff --git a/plugins/check_load.c b/plugins/check_load.c index 4a38e6ce..bdb1e55d 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c @@ -45,7 +45,7 @@ void print_usage (void); float wload1 = -1, wload5 = -1, wload15 = -1; float cload1 = -1, cload5 = -1, cload15 = -1; -char *status_line = ""; +char *status_line; @@ -72,7 +72,7 @@ main (int argc, char **argv) float la1, la5, la15; if (process_arguments (argc, argv) == ERROR) - usage ("\n"); + usage ("failed processing arguments\n"); #if HAVE_GETLOADAVG==1 result = getloadavg (la, 3); @@ -122,7 +122,7 @@ main (int argc, char **argv) # endif #endif - if ((la1 == -1) || (la5 == -1) || (la15 == -1)) { + if ((la1 < 0.0) || (la5 < 0.0) || (la15 < 0.0)) { #if HAVE_GETLOADAVG==1 printf (_("Error in getloadavg()\n")); #else diff --git a/plugins/check_mrtg.c b/plugins/check_mrtg.c index 2a9958d0..21efac2e 100644 --- a/plugins/check_mrtg.c +++ b/plugins/check_mrtg.c @@ -24,80 +24,10 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "common.h" #include "utils.h" -/* original command line: - <log_file> <expire_minutes> <AVG|MAX> <variable> <vwl> <vcl> <label> [units] */ - -void -print_usage (void) -{ - printf (_("\ -Usage: %s -F log_file -a <AVG | MAX> -v variable -w warning -c critical\n\ - [-l label] [-u units] [-e expire_minutes] [-t timeout] [-v]\n"), progname); - printf (_(UT_HLP_VRS), progname, progname); -} - -void -print_help (void) -{ - print_revision (progname, revision); - - printf (_(COPYRIGHT), copyright, email); - - printf(_("\ -This plugin will check either the average or maximum value of one of the\n\ -two variables recorded in an MRTG log file.\n")); - - print_usage (); - - printf (_(UT_HELP_VRSN)); - - printf (_("\ - -F, --logfile=FILE\n\ - The MRTG log file containing the data you want to monitor\n\ - -e, --expires=MINUTES\n\ - Minutes before MRTG data is considered to be too old\n\ - -a, --aggregation=AVG|MAX\n\ - Should we check average or maximum values?\n\ - -v, --variable=INTEGER\n\ - Which variable set should we inspect? (1 or 2)\n\ - -w, --warning=INTEGER\n\ - Threshold value for data to result in WARNING status\n\ - -c, --critical=INTEGER\n\ - Threshold value for data to result in CRITICAL status\n")); - - printf (_("\ - -l, --label=STRING\n\ - Type label for data (Examples: Conns, \"Processor Load\", In, Out)\n\ - -u, --units=STRING\n\ - Option units label for data (Example: Packets/Sec, Errors/Sec, \n\ - \"Bytes Per Second\", \"%% Utilization\")\n")); - - printf (_("\ -If the value exceeds the <vwl> threshold, a WARNING status is returned. If\n\ -the value exceeds the <vcl> threshold, a CRITICAL status is returned. If\n\ -the data in the log file is older than <expire_minutes> old, a WARNING\n\ -status is returned and a warning message is printed.\n\n")); - - printf(_("This plugin is useful for monitoring MRTG data that does not correspond to\n\ -bandwidth usage. (Use the check_mrtgtraf plugin for monitoring bandwidth).\n\ -It can be used to monitor any kind of data that MRTG is monitoring - errors,\n\ -packets/sec, etc. I use MRTG in conjuction with the Novell NLM that allows\n\ -me to track processor utilization, user connections, drive space, etc and\n\ -this plugin works well for monitoring that kind of data as well.\n\n")); - - printf (_("Notes:\n\ -- This plugin only monitors one of the two variables stored in the MRTG log\n\ - file. If you want to monitor both values you will have to define two\n\ - commands with different values for the <variable> argument. Of course,\n\ - you can always hack the code to make this plugin work for you...\n\ -- MRTG stands for the Multi Router Traffic Grapher. It can be downloaded from\n\ - http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html\n")); - - printf (_(UT_SUPPORT)); -} - int process_arguments (int, char **); int validate_arguments (void); +void print_help (void); +void print_usage (void); char *log_file = NULL; int expire_minutes = 0; @@ -105,8 +35,8 @@ int use_average = TRUE; int variable_number = -1; unsigned long value_warning_threshold = 0L; unsigned long value_critical_threshold = 0L; -char *value_label = ""; -char *units_label = ""; +char *value_label; +char *units_label; int main (int argc, char **argv) @@ -351,5 +281,92 @@ validate_arguments (void) if (variable_number == -1) usage (_("You must supply the variable number\n")); + if (value_label == NULL) + value_label = strdup (""); + + if (units_label == NULL) + units_label = strdup (""); + return OK; } + + + + + + +void +print_help (void) +{ + print_revision (progname, revision); + + printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n")); + printf (_(COPYRIGHT), copyright, email); + + printf(_("\ +This plugin will check either the average or maximum value of one of the\n\ +two variables recorded in an MRTG log file.\n")); + + print_usage (); + + printf (_(UT_HELP_VRSN)); + + printf (_("\ + -F, --logfile=FILE\n\ + The MRTG log file containing the data you want to monitor\n\ + -e, --expires=MINUTES\n\ + Minutes before MRTG data is considered to be too old\n\ + -a, --aggregation=AVG|MAX\n\ + Should we check average or maximum values?\n\ + -v, --variable=INTEGER\n\ + Which variable set should we inspect? (1 or 2)\n\ + -w, --warning=INTEGER\n\ + Threshold value for data to result in WARNING status\n\ + -c, --critical=INTEGER\n\ + Threshold value for data to result in CRITICAL status\n")); + + printf (_("\ + -l, --label=STRING\n\ + Type label for data (Examples: Conns, \"Processor Load\", In, Out)\n\ + -u, --units=STRING\n\ + Option units label for data (Example: Packets/Sec, Errors/Sec, \n\ + \"Bytes Per Second\", \"%% Utilization\")\n")); + + printf (_("\ +If the value exceeds the <vwl> threshold, a WARNING status is returned. If\n\ +the value exceeds the <vcl> threshold, a CRITICAL status is returned. If\n\ +the data in the log file is older than <expire_minutes> old, a WARNING\n\ +status is returned and a warning message is printed.\n\n")); + + printf(_("This plugin is useful for monitoring MRTG data that does not correspond to\n\ +bandwidth usage. (Use the check_mrtgtraf plugin for monitoring bandwidth).\n\ +It can be used to monitor any kind of data that MRTG is monitoring - errors,\n\ +packets/sec, etc. I use MRTG in conjuction with the Novell NLM that allows\n\ +me to track processor utilization, user connections, drive space, etc and\n\ +this plugin works well for monitoring that kind of data as well.\n\n")); + + printf (_("Notes:\n\ +- This plugin only monitors one of the two variables stored in the MRTG log\n\ + file. If you want to monitor both values you will have to define two\n\ + commands with different values for the <variable> argument. Of course,\n\ + you can always hack the code to make this plugin work for you...\n\ +- MRTG stands for the Multi Router Traffic Grapher. It can be downloaded from\n\ + http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html\n")); + + printf (_(UT_SUPPORT)); +} + + + + +/* original command line: + <log_file> <expire_minutes> <AVG|MAX> <variable> <vwl> <vcl> <label> [units] */ + +void +print_usage (void) +{ + printf (_("\ +Usage: %s -F log_file -a <AVG | MAX> -v variable -w warning -c critical\n\ + [-l label] [-u units] [-e expire_minutes] [-t timeout] [-v]\n"), progname); + printf (_(UT_HLP_VRS), progname, progname); +} diff --git a/plugins/check_mrtgtraf.c b/plugins/check_mrtgtraf.c index ce9ab191..be2f562e 100644 --- a/plugins/check_mrtgtraf.c +++ b/plugins/check_mrtgtraf.c @@ -24,60 +24,10 @@ const char *revision = "$Revision$"; const char *copyright = "1999-2003"; const char *email = "nagiosplug-devel@lists.sourceforge.net"; -void -print_usage (void) -{ - printf (_("\ -Usage: %s -F <log_file> -a <AVG | MAX> -v <variable> -w <warning_pair> -c <critical_pair>\n\ - [-e expire_minutes] [-t timeout] [-v]\n"), progname); - printf (_(UT_HLP_VRS), progname, progname); -} - -void -print_help (void) -{ - print_revision (progname, revision); - - printf (_(COPYRIGHT), copyright, email); - - print_usage (); - - printf (_(UT_HELP_VRSN)); - - printf (_("\ - -F, --filename=STRING\n\ - File to read log from\n\ - -e, --expires=INTEGER\n\ - Minutes after which log expires\n\ - -a, --aggregation=(AVG|MAX)\n\ - Test average or maximum\n\ - -w, --warning\n\ - Warning threshold pair \"<incoming>,<outgoing>\"\n\ - -c, --critical\n\ - Critical threshold pair \"<incoming>,<outgoing>\"\n")); - - printf (_("\n\ -This plugin will check the incoming/outgoing transfer rates of a router,\n\ -switch, etc recorded in an MRTG log. If the newest log entry is older\n\ -than <expire_minutes>, a WARNING status is returned. If either the\n\ -incoming or outgoing rates exceed the <icl> or <ocl> thresholds (in\n\ -Bytes/sec), a CRITICAL status results. If either of the rates exceed\n\ -the <iwl> or <owl> thresholds (in Bytes/sec), a WARNING status results.\n\n")); - - printf (_("Notes:\n\ -- MRTG stands for Multi Router Traffic Grapher. It can be downloaded from\n\ - http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html\n\ -- While MRTG can monitor things other than traffic rates, this\n\ - plugin probably won't work with much else without modification.\n\ -- The calculated i/o rates are a little off from what MRTG actually\n\ - reports. I'm not sure why this is right now, but will look into it\n\ - for future enhancements of this plugin.\n")); - - printf (_(UT_SUPPORT)); -} - int process_arguments (int, char **); int validate_arguments (void); +void print_help(void); +void print_usage(void); char *log_file = NULL; int expire_minutes = -1; @@ -87,6 +37,10 @@ unsigned long incoming_critical_threshold = 0L; unsigned long outgoing_warning_threshold = 0L; unsigned long outgoing_critical_threshold = 0L; + + + + int main (int argc, char **argv) { @@ -357,3 +311,64 @@ validate_arguments (void) { return OK; } + + + + + + +void +print_help (void) +{ + print_revision (progname, revision); + + printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n")); + printf (_(COPYRIGHT), copyright, email); + + print_usage (); + + printf (_(UT_HELP_VRSN)); + + printf (_("\ + -F, --filename=STRING\n\ + File to read log from\n\ + -e, --expires=INTEGER\n\ + Minutes after which log expires\n\ + -a, --aggregation=(AVG|MAX)\n\ + Test average or maximum\n\ + -w, --warning\n\ + Warning threshold pair \"<incoming>,<outgoing>\"\n\ + -c, --critical\n\ + Critical threshold pair \"<incoming>,<outgoing>\"\n")); + + printf (_("\n\ +This plugin will check the incoming/outgoing transfer rates of a router,\n\ +switch, etc recorded in an MRTG log. If the newest log entry is older\n\ +than <expire_minutes>, a WARNING status is returned. If either the\n\ +incoming or outgoing rates exceed the <icl> or <ocl> thresholds (in\n\ +Bytes/sec), a CRITICAL status results. If either of the rates exceed\n\ +the <iwl> or <owl> thresholds (in Bytes/sec), a WARNING status results.\n\n")); + + printf (_("Notes:\n\ +- MRTG stands for Multi Router Traffic Grapher. It can be downloaded from\n\ + http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html\n\ +- While MRTG can monitor things other than traffic rates, this\n\ + plugin probably won't work with much else without modification.\n\ +- The calculated i/o rates are a little off from what MRTG actually\n\ + reports. I'm not sure why this is right now, but will look into it\n\ + for future enhancements of this plugin.\n")); + + printf (_(UT_SUPPORT)); +} + + + + +void +print_usage (void) +{ + printf (_("\ +Usage: %s -F <log_file> -a <AVG | MAX> -v <variable> -w <warning_pair> -c <critical_pair>\n\ + [-e expire_minutes] [-t timeout] [-v]\n"), progname); + printf (_(UT_HLP_VRS), progname, progname); +} diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c index de8a6200..4b227269 100644 --- a/plugins/check_nwstat.c +++ b/plugins/check_nwstat.c @@ -75,9 +75,14 @@ enum checkvar vars_to_check = NONE; int sap_number=-1; int process_arguments(int, char **); -void print_usage(void); void print_help(void); +void print_usage(void); + + + + + int main(int argc, char **argv) { int result; @@ -878,15 +883,12 @@ int process_arguments(int argc, char **argv) { return OK; } - -void print_usage(void) -{ - printf (_("\ -Usage: %s -H host [-p port] [-v variable] [-w warning] [-c critical]\n\ - [-t timeout].\n"), progname); - printf (_(UT_HLP_VRS), progname, progname); -} + + + + + void print_help(void) { char *myport; @@ -894,7 +896,7 @@ void print_help(void) print_revision (progname, revision); - printf (_("Copyright (c) 1999-2001 Ethan Galstad <nagios@nagios.org>\n")); + printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n")); printf (_(COPYRIGHT), copyright, email); printf (_("\ @@ -972,3 +974,14 @@ Notes:\n\ printf (_(UT_SUPPORT)); } + + + + +void print_usage(void) +{ + printf (_("\ +Usage: %s -H host [-p port] [-v variable] [-w warning] [-c critical]\n\ + [-t timeout].\n"), progname); + printf (_(UT_HLP_VRS), progname, progname); +} diff --git a/plugins/check_overcr.c b/plugins/check_overcr.c index 5f50ca7e..9958432e 100644 --- a/plugins/check_overcr.c +++ b/plugins/check_overcr.c @@ -106,17 +106,20 @@ main (int argc, char **argv) temp_ptr = (char *) strtok (recv_buffer, "\r\n"); if (temp_ptr == NULL) die (STATE_CRITICAL, _("Invalid response from server - no load information\n")); - load_1min = strtod (temp_ptr, NULL); + else + load_1min = strtod (temp_ptr, NULL); temp_ptr = (char *) strtok (NULL, "\r\n"); if (temp_ptr == NULL) die (STATE_CRITICAL, _("Invalid response from server after load 1\n")); - load_5min = strtod (temp_ptr, NULL); + else + load_5min = strtod (temp_ptr, NULL); temp_ptr = (char *) strtok (NULL, "\r\n"); if (temp_ptr == NULL) die (STATE_CRITICAL, _("Invalid response from server after load 5\n")); - load_15min = strtod (temp_ptr, NULL); + else + load_15min = strtod (temp_ptr, NULL); switch (vars_to_check) { case LOAD1: @@ -160,7 +163,8 @@ main (int argc, char **argv) temp_ptr = (char *) strtok (NULL, "%"); if (temp_ptr == NULL) die (STATE_CRITICAL, _("Invalid response from server\n")); - percent_used_disk_space = strtoul (temp_ptr, NULL, 10); + else + percent_used_disk_space = strtoul (temp_ptr, NULL, 10); break; } @@ -186,8 +190,8 @@ main (int argc, char **argv) if (result != STATE_OK) die (result, _("Unknown error fetching network status\n")); - - port_connections = strtod (recv_buffer, NULL); + else + port_connections = strtod (recv_buffer, NULL); if (check_critical_value == TRUE && (port_connections >= critical_value)) result = STATE_CRITICAL; @@ -215,8 +219,8 @@ main (int argc, char **argv) temp_ptr = (char *) strtok (NULL, ")"); if (temp_ptr == NULL) die (STATE_CRITICAL, _("Invalid response from server\n")); - - processes = strtod (temp_ptr, NULL); + else + processes = strtod (temp_ptr, NULL); if (check_critical_value == TRUE && (processes >= critical_value)) result = STATE_CRITICAL; @@ -264,11 +268,11 @@ main (int argc, char **argv) } /* reset timeout */ - alarm (0); +/* alarm (0); */ - printf (_("Reached end of program with no data returned\n")); +/* printf (_("Reached end of program with no data returned\n")); */ - return result; +/* return result; */ } diff --git a/plugins/check_ping.c b/plugins/check_ping.c index 26c0192a..fd73b8ce 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c @@ -55,7 +55,7 @@ int verbose = FALSE; float rta = UNKNOWN_TRIP_TIME; int pl = UNKNOWN_PACKET_LOSS; -char *warn_text = ""; +char *warn_text; @@ -69,11 +69,10 @@ main (int argc, char **argv) int this_result = STATE_UNKNOWN; int i; - addresses = malloc (max_addr); + addresses = malloc ((size_t)max_addr); if (process_arguments (argc, argv) == ERROR) usage (_("Could not parse arguments")); - exit; /* Set signal handling and alarm */ if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { @@ -113,7 +112,7 @@ main (int argc, char **argv) /* run the command */ this_result = run_ping (cmd, addresses[i]); - if (pl == UNKNOWN_PACKET_LOSS || rta == UNKNOWN_TRIP_TIME) { + if (pl == UNKNOWN_PACKET_LOSS || rta < 0.0) { printf ("%s\n", cmd); die (STATE_UNKNOWN, _("Error: Could not interpret output from ping command\n")); @@ -193,12 +192,15 @@ process_arguments (int argc, char **argv) switch (c) { case '?': /* usage */ usage3 (_("Unknown argument"), optopt); + break; case 'h': /* help */ print_help (); exit (STATE_OK); + break; case 'V': /* version */ print_revision (progname, revision); exit (STATE_OK); + break; case 't': /* timeout period */ timeout_interval = atoi (optarg); break; @@ -221,7 +223,7 @@ process_arguments (int argc, char **argv) n_addresses++; if (n_addresses > max_addr) { max_addr *= 2; - addresses = realloc (addresses, max_addr); + addresses = realloc (addresses, (size_t)max_addr); if (addresses == NULL) die (STATE_UNKNOWN, _("Could not realloc() addresses\n")); } @@ -292,7 +294,7 @@ process_arguments (int argc, char **argv) } } - if (wrta == UNKNOWN_TRIP_TIME) { + if (wrta < 0.0) { if (is_negative (argv[c])) { printf (_("<wrta> (%s) must be a non-negative number\n"), argv[c]); return ERROR; @@ -303,7 +305,7 @@ process_arguments (int argc, char **argv) } } - if (crta == UNKNOWN_TRIP_TIME) { + if (crta < 0.0) { if (is_negative (argv[c])) { printf (_("<crta> (%s) must be a non-negative number\n"), argv[c]); return ERROR; @@ -346,11 +348,11 @@ validate_arguments () float max_seconds; int i; - if (wrta == UNKNOWN_TRIP_TIME) { + if (wrta < 0.0) { printf (_("<wrta> was not set\n")); return ERROR; } - else if (crta == UNKNOWN_TRIP_TIME) { + else if (crta < 0.0) { printf (_("<crta> was not set\n")); return ERROR; } @@ -397,10 +399,9 @@ run_ping (char *cmd, char *server_address) char buf[MAX_INPUT_BUFFER]; int result = STATE_UNKNOWN; - if ((child_process = spopen (cmd)) == NULL) { - printf (_("Cannot open pipe: ")); - die (STATE_UNKNOWN, cmd); - } + if ((child_process = spopen (cmd)) == NULL) + die (STATE_UNKNOWN, _("Cannot open pipe: %s"), cmd); + child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); if (child_stderr == NULL) printf (_("Cannot open stderr for %s\n"), cmd); @@ -455,7 +456,7 @@ run_ping (char *cmd, char *server_address) _("PING CRITICAL - Host not found (%s)"), server_address); - if (strlen (warn_text) == 0) + if (warn_text == NULL) warn_text = strdup (buf); else if (asprintf (&warn_text, "%s %s", warn_text, buf) == -1) die (STATE_UNKNOWN, _("unable to realloc warn_text")); @@ -472,6 +473,9 @@ run_ping (char *cmd, char *server_address) if (spclose (child_process)) result = max_state (result, STATE_WARNING); + if (warn_text == NULL) + warn_text = strdup(""); + return result; } diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 1b641c55..1894b281 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c @@ -49,12 +49,14 @@ int options = 0; /* bitmask of filter criteria to test against */ #define PCPU 256 /* Different metrics */ -int metric = 0; -#define METRIC_PROCS 0 -#define METRIC_VSZ 1 -#define METRIC_RSS 2 -#define METRIC_CPU 3 -char *metric_name = ""; +char *metric_name; +enum metric { + METRIC_PROCS, + METRIC_VSZ, + METRIC_RSS, + METRIC_CPU +}; +enum metric metric = METRIC_PROCS; int verbose = 0; int uid; @@ -62,11 +64,11 @@ int ppid; int vsz; int rss; float pcpu; -char *statopts = ""; -char *prog = ""; -char *args = ""; -char *fmt = ""; -char *fails = ""; +char *statopts; +char *prog; +char *args; +char *fmt; +char *fails; char tmp[MAX_INPUT_BUFFER]; @@ -317,54 +319,35 @@ process_arguments (int argc, char **argv) print_revision (progname, revision); exit (STATE_OK); case 't': /* timeout period */ - if (!is_integer (optarg)) { - printf (_("%s: Timeout Interval must be an integer!\n\n"), - progname); - print_usage (); - exit (STATE_UNKNOWN); - } - timeout_interval = atoi (optarg); + if (!is_integer (optarg)) + usage (_("Timeout Interval must be an integer!\n\n")); + else + timeout_interval = atoi (optarg); break; case 'c': /* critical threshold */ - if (is_integer (optarg)) { + if (is_integer (optarg)) cmax = atoi (optarg); + else if (sscanf (optarg, ":%d", &cmax) == 1) break; - } - else if (sscanf (optarg, ":%d", &cmax) == 1) { + else if (sscanf (optarg, "%d:%d", &cmin, &cmax) == 2) break; - } - else if (sscanf (optarg, "%d:%d", &cmin, &cmax) == 2) { + else if (sscanf (optarg, "%d:", &cmin) == 1) break; - } - else if (sscanf (optarg, "%d:", &cmin) == 1) { - break; - } - else { - printf (_("%s: Critical Process Count must be an integer!\n\n"), - progname); - print_usage (); - exit (STATE_UNKNOWN); - } + else + usage (_("Critical Process Count must be an integer!\n\n")); + break; case 'w': /* warning time threshold */ - if (is_integer (optarg)) { + if (is_integer (optarg)) wmax = atoi (optarg); + else if (sscanf (optarg, ":%d", &wmax) == 1) break; - } - else if (sscanf (optarg, ":%d", &wmax) == 1) { - break; - } - else if (sscanf (optarg, "%d:%d", &wmin, &wmax) == 2) { + else if (sscanf (optarg, "%d:%d", &wmin, &wmax) == 2) break; - } - else if (sscanf (optarg, "%d:", &wmin) == 1) { + else if (sscanf (optarg, "%d:", &wmin) == 1) break; - } - else { - printf (_("%s: Warning Process Count must be an integer!\n\n"), - progname); - print_usage (); - exit (STATE_UNKNOWN); - } + else + usage (_("%s: Warning Process Count must be an integer!\n\n")); + break; case 'p': /* process id */ if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) { asprintf (&fmt, "%s%sPPID = %d", fmt, (options ? ", " : ""), ppid); @@ -376,7 +359,10 @@ process_arguments (int argc, char **argv) print_usage (); exit (STATE_UNKNOWN); case 's': /* status */ - asprintf (&statopts, "%s", optarg); + if (statopts) + break; + else + statopts = strdup(optarg); asprintf (&fmt, _("%s%sSTATE = %s"), fmt, (options ? ", " : ""), statopts); options |= STAT; break; @@ -408,13 +394,19 @@ process_arguments (int argc, char **argv) options |= USER; break; case 'C': /* command */ - asprintf (&prog, "%s", optarg); + if (prog) + break; + else + prog = strdup(optarg); asprintf (&fmt, _("%s%scommand name '%s'"), fmt, (options ? ", " : ""), prog); options |= PROG; break; case 'a': /* args (full path name with args) */ - asprintf (&args, "%s", optarg); + if (args) + break; + else + args = strdup(optarg); asprintf (&fmt, _("%s%sargs '%s'"), fmt, (options ? ", " : ""), args); options |= ARGS; break; @@ -521,6 +513,21 @@ validate_arguments () if (options == 0) options = ALL; + if (statopts==NULL) + statopts = strdup(""); + + if (prog==NULL) + prog = strdup(""); + + if (args==NULL) + args = strdup(""); + + if (fmt==NULL) + fmt = strdup(""); + + if (fails==NULL) + fails = strdup(""); + return options; } diff --git a/plugins/check_real.c b/plugins/check_real.c index ecdd5619..9c9c3e0b 100644 --- a/plugins/check_real.c +++ b/plugins/check_real.c @@ -38,10 +38,10 @@ void print_help (void); void print_usage (void); int server_port = PORT; -char *server_address = ""; -char *host_name = ""; +char *server_address; +char *host_name; char *server_url = NULL; -char *server_expect = EXPECT; +char *server_expect; int warning_time = 0; int check_warning_time = FALSE; int critical_time = 0; @@ -294,18 +294,18 @@ process_arguments (int argc, char **argv) switch (c) { case 'I': /* hostname */ case 'H': /* hostname */ - if (is_host (optarg)) { - server_address = optarg; - } - else { + if (server_address) + break; + else if (is_host (optarg)) + server_address = strdup(optarg); + else usage (_("Invalid host name\n")); - } break; case 'e': /* string to expect in response header */ - server_expect = optarg; + server_expect = strdup(optarg); break; case 'u': /* server URL */ - server_url = optarg; + server_url = strdup(optarg); break; case 'p': /* port */ if (is_intpos (optarg)) { @@ -356,7 +356,7 @@ process_arguments (int argc, char **argv) } c = optind; - if (strlen(server_address)==0 && argc>c) { + if (server_address==NULL && argc>c) { if (is_host (argv[c])) { server_address = argv[c++]; } @@ -365,11 +365,14 @@ process_arguments (int argc, char **argv) } } - if (strlen(server_address) == 0) + if (server_address==NULL) usage (_("You must provide a server to check\n")); - if (strlen(host_name) == 0) - asprintf (&host_name, "%s", server_address); + if (host_name==NULL) + host_name = strdup (server_address); + + if (server_expect == NULL) + server_expect = strdup(EXPECT); return validate_arguments (); } diff --git a/plugins/utils.c b/plugins/utils.c index 518caa8c..5b975729 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -52,14 +52,14 @@ max_state (int a, int b) return max (a, b); } -void usage (char *msg) +void usage (const char *msg) { printf ("%s", msg); print_usage (); exit (STATE_UNKNOWN); } -void usage2(char *msg, char *arg) +void usage2(const char *msg, const char *arg) { printf ("%s: %s - %s\n",progname,msg,arg); print_usage (); @@ -67,7 +67,7 @@ void usage2(char *msg, char *arg) } void -usage3 (char *msg, int arg) +usage3 (const char *msg, int arg) { printf ("%s: %s - %c\n", progname, msg, arg); print_usage(); diff --git a/plugins/utils.h b/plugins/utils.h index b763b1e2..efdbed41 100644 --- a/plugins/utils.h +++ b/plugins/utils.h @@ -71,9 +71,9 @@ char *strpcat (char *dest, const char *src, const char *str); int max_state (int a, int b); -void usage (char *msg) __attribute__((noreturn)); -void usage2(char *msg, char *arg) __attribute__((noreturn)); -void usage3(char *msg, int arg) __attribute__((noreturn)); +void usage (const char *msg) __attribute__((noreturn)); +void usage2(const char *msg, const char *arg) __attribute__((noreturn)); +void usage3(const char *msg, int arg) __attribute__((noreturn)); const char *state_text (int result); |