diff options
author | M. Sean Finney <seanius@users.sourceforge.net> | 2005-06-28 00:26:53 +0000 |
---|---|---|
committer | M. Sean Finney <seanius@users.sourceforge.net> | 2005-06-28 00:26:53 +0000 |
commit | d4c0948266f261525e12c58d58e0fc68987a9818 (patch) | |
tree | e7d8e6afe6c425a1e51446ace47b0fc4e99dcfd0 | |
parent | f573447d1f6dbf25b58bbfea81226a2ae3736555 (diff) | |
download | monitoring-plugins-d4c0948266f261525e12c58d58e0fc68987a9818.tar.gz |
scanf parsing fix for check_swap from tracker id 1123292. now use floor(3)
to round down floating point numbers. requires -lm on many systems,
so support for testing for this was added to the configure.in and
automake template
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1194 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r-- | configure.in | 7 | ||||
-rw-r--r-- | plugins/Makefile.am | 3 | ||||
-rw-r--r-- | plugins/check_swap.c | 18 |
3 files changed, 18 insertions, 10 deletions
diff --git a/configure.in b/configure.in index df516c54..b209d19a 100644 --- a/configure.in +++ b/configure.in @@ -137,6 +137,11 @@ AC_CHECK_LIB(socket,socket,SOCKETLIBS="$SOCKETLIBS -lsocket") AC_CHECK_LIB(resolv,main,SOCKETLIBS="$SOCKETLIBS -lresolv") AC_SUBST(SOCKETLIBS) +dnl +dnl check for math-related functions needing -lm +AC_CHECK_LIB(m,floor,MATHLIBS="-lm") +AC_SUBST(MATHLIBS) + dnl Check for PostgreSQL libraries _SAVEDLIBS="$LIBS" _SAVEDCPPFLAGS="$CPPFLAGS" @@ -567,7 +572,7 @@ AC_TRY_COMPILE([#include <sys/time.h>], AC_DEFINE(NEED_GETTIMEOFDAY,1,[Define if gettimeofday is needed]))) dnl Checks for library functions. -AC_CHECK_FUNCS(memmove select socket strdup strstr strtod strtol strtoul) +AC_CHECK_FUNCS(memmove select socket strdup strstr strtod strtol strtoul, floor) AC_MSG_CHECKING(return type of socket size) AC_TRY_COMPILE([#include <stdlib.h> diff --git a/plugins/Makefile.am b/plugins/Makefile.am index d983192b..87a97a9f 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -9,6 +9,7 @@ datadir = @datadir@ localedir = $(datadir)/locale DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ LIBS = @LIBINTL@ @LIBS@ @SSLINCLUDE@ +MATHLIBS = @MATHLIBS@ libexec_PROGRAMS = check_dhcp check_disk check_dummy check_http check_load \ check_mrtg check_mrtgtraf check_nwstat check_overcr check_ping \ @@ -72,7 +73,7 @@ check_real_LDADD = $(NETLIBS) check_snmp_LDADD = $(BASEOBJS) popen.o check_smtp_LDADD = $(NETLIBS) $(SSLLIBS) check_ssh_LDADD = $(NETLIBS) -check_swap_LDADD = $(BASEOBJS) popen.o +check_swap_LDADD = $(MATHLIBS) $(BASEOBJS) popen.o check_tcp_LDADD = $(NETLIBS) $(SSLLIBS) check_time_LDADD = $(NETLIBS) check_udp_LDADD = $(NETLIBS) diff --git a/plugins/check_swap.c b/plugins/check_swap.c index fe9254d2..8f5ebf8e 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c @@ -42,8 +42,8 @@ void print_help (void); int warn_percent = 0; int crit_percent = 0; -float warn_size = 0; -float crit_size = 0; +double warn_size = 0; +double crit_size = 0; int verbose; int allswaps; @@ -376,12 +376,13 @@ process_arguments (int argc, char **argv) switch (c) { case 'w': /* warning size threshold */ if (is_intnonneg (optarg)) { - warn_size = (float) atoi (optarg); + warn_size = (double) atoi (optarg); break; } else if (strstr (optarg, ",") && strstr (optarg, "%") && - sscanf (optarg, "%.0f,%d%%", &warn_size, &warn_percent) == 2) { + sscanf (optarg, "%g,%d%%", &warn_size, &warn_percent) == 2) { + warn_size = floor(warn_size); break; } else if (strstr (optarg, "%") && @@ -393,12 +394,13 @@ process_arguments (int argc, char **argv) } case 'c': /* critical size threshold */ if (is_intnonneg (optarg)) { - crit_size = (float) atoi (optarg); + crit_size = (double) atoi (optarg); break; } else if (strstr (optarg, ",") && strstr (optarg, "%") && - sscanf (optarg, "%.0f,%d%%", &crit_size, &crit_percent) == 2) { + sscanf (optarg, "%g,%d%%", &crit_size, &crit_percent) == 2) { + crit_size = floor(crit_size); break; } else if (strstr (optarg, "%") && @@ -439,12 +441,12 @@ process_arguments (int argc, char **argv) if (c == argc) return validate_arguments (); if (warn_size == 0 && is_intnonneg (argv[c])) - warn_size = (float) atoi (argv[c++]); + warn_size = (double) atoi (argv[c++]); if (c == argc) return validate_arguments (); if (crit_size == 0 && is_intnonneg (argv[c])) - crit_size = atoi (argv[c++]); + crit_size = (double) atoi (argv[c++]); return validate_arguments (); } |