From 3038819fef47495af2730b0d2df2a5a8475fc7bb Mon Sep 17 00:00:00 2001 From: "M. Sean Finney" Date: Mon, 31 Oct 2005 20:03:19 +0000 Subject: code cleanups, largely resulting from turning on -Wall. mostly unused variables and explicit casting issues, but there were a couple gotchas in there too. git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1267 f882894a-f735-0410-b71e-b25c423dba1c diff --git a/configure.in b/configure.in index 368bbf7..a3dbd72 100644 --- a/configure.in +++ b/configure.in @@ -162,6 +162,7 @@ AC_SUBST(SOCKETLIBS) dnl dnl check for math-related functions needing -lm +AC_CHECK_HEADERS(math.h) AC_CHECK_LIB(m,floor,MATHLIBS="-lm") AC_SUBST(MATHLIBS) @@ -909,6 +910,10 @@ if test -n "$ac_cv_ps_varlist" ; then AC_DEFINE_UNQUOTED(PS_COLS,$ac_cv_ps_cols, [Number of columns in ps command]) EXTRAS="$EXTRAS check_procs check_nagios" + if echo "$ac_cv_ps_varlist" | grep -q "procetime"; then + AC_DEFINE(PS_USES_PROCETIME,"yes", + [Whether the ps utility uses the "procetime" field]) + fi fi AC_PATH_PROG(PATH_TO_PING,ping) diff --git a/plugins/check_game.c b/plugins/check_game.c index 912072c..8548bbd 100644 --- a/plugins/check_game.c +++ b/plugins/check_game.c @@ -56,7 +56,6 @@ main (int argc, char **argv) { char *command_line; int result = STATE_UNKNOWN; - FILE *fp; char *p, *ret[QSTAT_MAX_RETURN_ARGS]; size_t i = 0; output chld_out; diff --git a/plugins/check_http.c b/plugins/check_http.c index 413d501..9ff572e 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -746,9 +746,6 @@ check_http (void) double elapsed_time; int page_len = 0; int result = STATE_UNKNOWN; -#ifdef HAVE_SSL - int sslerr; -#endif /* try to connect to the host at the given port number */ if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) @@ -793,7 +790,7 @@ check_http (void) asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf); } - asprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, strlen (http_post_data)); + asprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, (int)strlen (http_post_data)); asprintf (&buf, "%s%s%s", buf, http_post_data, CRLF); } else { @@ -858,7 +855,7 @@ check_http (void) if (verbose) printf ("%s://%s:%d%s is %d characters\n", use_ssl ? "https" : "http", server_address, - server_port, server_url, pagesize); + server_port, server_url, (int)pagesize); /* find status line and null-terminate it */ status_line = page; diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c index 0ae488f..ab9c877 100644 --- a/plugins/check_nagios.c +++ b/plugins/check_nagios.c @@ -55,9 +55,9 @@ main (int argc, char **argv) int procrss = 0; float procpcpu = 0; char procstat[8]; - /* procetime is unused in most configurations, but may be in PS_VAR_LIST - * so it must be here in spite of it producing compiler warnings */ +#ifdef PS_USES_PROCETIME char procetime[MAX_INPUT_BUFFER]; +#endif /* PS_USES_PROCETIME */ char procprog[MAX_INPUT_BUFFER]; char *procargs; int pos, cols; diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 97c86a3..db106f2 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -578,7 +578,7 @@ process_arguments (int argc, char **argv) labels_size += 8; labels = realloc (labels, labels_size); if (labels == NULL) - die (STATE_UNKNOWN, _("Could not reallocate labels[%d]"), nlabels); + die (STATE_UNKNOWN, _("Could not reallocate labels[%d]"), (int)nlabels); } labels[nlabels - 1] = optarg; ptr = thisarg (optarg); @@ -607,7 +607,7 @@ process_arguments (int argc, char **argv) unitv_size += 8; unitv = realloc (unitv, unitv_size); if (unitv == NULL) - die (STATE_UNKNOWN, _("Could not reallocate units [%d]\n"), nunits); + die (STATE_UNKNOWN, _("Could not reallocate units [%d]\n"), (int)nunits); } unitv[nunits - 1] = optarg; ptr = thisarg (optarg); diff --git a/plugins/check_swap.c b/plugins/check_swap.c index aeeb9ba..74b9daf 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c @@ -385,7 +385,7 @@ process_arguments (int argc, char **argv) } else if (strstr (optarg, ",") && strstr (optarg, "%") && - sscanf (optarg, "%g,%d%%", &warn_size, &warn_percent) == 2) { + sscanf (optarg, "%lf,%d%%", &warn_size, &warn_percent) == 2) { warn_size = floor(warn_size); break; } @@ -403,7 +403,7 @@ process_arguments (int argc, char **argv) } else if (strstr (optarg, ",") && strstr (optarg, "%") && - sscanf (optarg, "%g,%d%%", &crit_size, &crit_percent) == 2) { + sscanf (optarg, "%lf,%d%%", &crit_size, &crit_percent) == 2) { crit_size = floor(crit_size); break; } diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index 2a77637..cb7a869 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c @@ -31,7 +31,6 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #ifdef HAVE_SSL static int check_cert = FALSE; static int days_till_exp; -static char *randbuff = ""; # define my_recv(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) # define my_send(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0)) #else @@ -51,7 +50,6 @@ static char *QUIT = NULL; static int PROTOCOL = IPPROTO_TCP; /* most common is default */ static int PORT = 0; -static char timestamp[17] = ""; static int server_port = 0; static char *server_address = NULL; static char *server_send = NULL; @@ -199,7 +197,7 @@ main (int argc, char **argv) if(flags & FLAG_VERBOSE) { printf("Using service %s\n", SERVICE); printf("Port: %d\n", PORT); - printf("flags: 0x%x\n", flags); + printf("flags: 0x%x\n", (int)flags); } if(EXPECT && !server_expect_count) @@ -242,7 +240,7 @@ main (int argc, char **argv) } if(flags & FLAG_VERBOSE) { - printf("server_expect_count: %d\n", server_expect_count); + printf("server_expect_count: %d\n", (int)server_expect_count); for(i = 0; i < server_expect_count; i++) printf("\t%d: %s\n", i, server_expect[i]); } @@ -274,7 +272,7 @@ main (int argc, char **argv) /* print raw output if we're debugging */ if(flags & FLAG_VERBOSE) printf("received %d bytes from host\n#-raw-recv-------#\n%s\n#-raw-recv-------#\n", - len + 1, status); + (int)len + 1, status); while(isspace(status[len])) status[len--] = '\0'; for (i = 0; i < server_expect_count; i++) { diff --git a/plugins/common.h b/plugins/common.h index 5eac63e..b4699ce 100644 --- a/plugins/common.h +++ b/plugins/common.h @@ -45,7 +45,7 @@ #include #include -#ifdef HUGE_VAL_NEEDS_MATH_H +#ifdef HAVE_MATH_H #include #endif diff --git a/plugins/netutils.c b/plugins/netutils.c index 6f3a151..b4c3944 100644 --- a/plugins/netutils.c +++ b/plugins/netutils.c @@ -31,6 +31,8 @@ * ****************************************************************************/ +#define LOCAL_TIMEOUT_ALARM_HANDLER + #include "common.h" #include "netutils.h" @@ -217,14 +219,14 @@ np_net_connect (const char *host_name, int port, int *sd, int proto) /* else the hostname is interpreted as a path to a unix socket */ else { if(strlen(host_name) >= UNIX_PATH_MAX){ - die(_("Supplied path too long unix domain socket")); + die(STATE_UNKNOWN, _("Supplied path too long unix domain socket")); } memset(&su, 0, sizeof(su)); su.sun_family = AF_UNIX; strncpy(su.sun_path, host_name, UNIX_PATH_MAX); *sd = socket(PF_UNIX, SOCK_STREAM, 0); if(sd < 0){ - die(_("Socket creation failed")); + die(STATE_UNKNOWN, _("Socket creation failed")); } result = connect(*sd, (struct sockaddr *)&su, sizeof(su)); if (result < 0 && errno == ECONNREFUSED) diff --git a/plugins/netutils.h b/plugins/netutils.h index 8bc7bd6..1168f9f 100644 --- a/plugins/netutils.h +++ b/plugins/netutils.h @@ -37,6 +37,7 @@ #include "config.h" #include "common.h" +#include "utils.h" #include #include @@ -77,6 +78,7 @@ int send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int is_host (const char *); int is_addr (const char *); int resolve_host_or_addr (const char *, int); +void host_or_die(const char *str); #define is_inet_addr(addr) resolve_host_or_addr(addr, AF_INET) #ifdef USE_IPV6 # define is_inet6_addr(addr) resolve_host_or_addr(addr, AF_INET6) diff --git a/plugins/sslutils.c b/plugins/sslutils.c index d785fb7..66c7299 100644 --- a/plugins/sslutils.c +++ b/plugins/sslutils.c @@ -31,6 +31,7 @@ * ****************************************************************************/ +#define LOCAL_TIMEOUT_ALARM_HANDLER #include "common.h" #include "netutils.h" -- cgit v0.10-9-g596f