diff --git a/configure.ac b/configure.ac index 5b0ce95..92ff82c 100644 --- a/configure.ac +++ b/configure.ac @@ -74,6 +74,12 @@ AC_CHECK_FUNCS([\ ]) AC_CHECK_DECL([strndupa]) +AC_CHECK_FUNCS([fpclassify], [], + [AC_CHECK_LIB([m], [fpclassify], [MATH_LIBS="-lm"])] + [AC_CHECK_LIB([m], [__fpclassify], [MATH_LIBS="-lm"])] +) +AC_SUBST([MATH_LIBS]) + AS_IF([test "x$ac_cv_func_open_memstream" = "xyes" && test "x$ac_cv_have_decl_strndupa" == "xyes"], [ build_mustach=yes AC_DEFINE([BUILD_MUSTACH], [1], [build mustach support]) diff --git a/src/Makemodule.am b/src/Makemodule.am index c072af3..e1c75f5 100644 --- a/src/Makemodule.am +++ b/src/Makemodule.am @@ -4,7 +4,7 @@ bin_PROGRAMS = dhcpd-pools AC_PROG_RANLIB = resolv AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib -I$(top_builddir)/lib -dhcpd_pools_LDADD = $(top_builddir)/lib/libdhcpd_pools.la +dhcpd_pools_LDADD = $(top_builddir)/lib/libdhcpd_pools.la $(MATH_LIBS) dhcpd_pools_SOURCES = \ src/analyze.c \ diff --git a/src/mustach-dhcpd-pools.c b/src/mustach-dhcpd-pools.c index 1019452..8fa1bec 100644 --- a/src/mustach-dhcpd-pools.c +++ b/src/mustach-dhcpd-pools.c @@ -64,10 +64,9 @@ static int must_enter(void *closure, const char *name); static int must_leave(void *closure); /* This can be called when template is invalid end put happens before enter. */ -int must_put_err(void *closure __attribute__ ((unused)), - const char *name __attribute__ ((unused)), - int escape __attribute__ ((unused)), - FILE *file __attribute__ ((unused))) +static int must_put_err(void *closure __attribute__ ((unused)), + const char *name __attribute__ ((unused)), + int escape __attribute__ ((unused)), FILE *file __attribute__ ((unused))) { return MUSTACH_ERROR_SYSTEM; } diff --git a/src/output.c b/src/output.c index 21d67f4..ebd841f 100644 --- a/src/output.c +++ b/src/output.c @@ -106,22 +106,21 @@ int shnet_output_helper(struct conf_t *state, struct output_helper_t *oh, { /* counts and calculations */ oh->tc = shared_p->touched + shared_p->used; - if (shared_p->available == 0) { + if (fpclassify(shared_p->available) == FP_ZERO) { oh->percent = NAN; oh->tcp = NAN; oh->bup = NAN; - } else { - oh->percent = (double)(100 * shared_p->used) / shared_p->available; - oh->tcp = - (double)((100 * (shared_p->touched + shared_p->used)) / shared_p->available); - if (state->backups_found == 1) { - oh->bup = (double)(100 * shared_p->backups) / shared_p->available; - } - } - /* set status */ - if (oh->percent == NAN) oh->status = STATUS_SUPPRESSED; - else if (shared_p->available <= state->minsize) + return 0; + } + + oh->percent = (double)(100 * shared_p->used) / shared_p->available; + oh->tcp = (double)((100 * (shared_p->touched + shared_p->used)) / shared_p->available); + if (state->backups_found == 1) + oh->bup = (double)(100 * shared_p->backups) / shared_p->available; + + /* set status */ + if (shared_p->available <= state->minsize) oh->status = STATUS_IGNORED; else if (state->critical < oh->percent && shared_p->used < state->crit_count) oh->status = STATUS_CRIT; @@ -503,18 +502,18 @@ static int output_json(struct conf_t *state, const int print_mac_addreses) fprintf(outfile, "\"used\":%g, ", shared_p->used); fprintf(outfile, "\"touched\":%g, ", shared_p->touched); fprintf(outfile, "\"free\":%g, ", shared_p->available - shared_p->used); - if (shared_p->available == 0) + if (fpclassify(shared_p->available) == FP_ZERO) fprintf(outfile, "\"percent\":\"%g\", ", oh.percent); else fprintf(outfile, "\"percent\":%g, ", oh.percent); fprintf(outfile, "\"touch_count\":%g, ", oh.tc); - if (shared_p->available == 0) + if (fpclassify(shared_p->available) == FP_ZERO) fprintf(outfile, "\"touch_percent\":\"%g\", ", oh.tcp); else fprintf(outfile, "\"touch_percent\":%g, ", oh.tcp); if (state->backups_found == 1) { fprintf(outfile, "\"backup_count\":%g, ", shared_p->backups); - if (shared_p->available == 0) + if (fpclassify(shared_p->available) == FP_ZERO) fprintf(outfile, "\"backup_percent\":\"%g\", ", oh.bup); else fprintf(outfile, "\"backup_percent\":%g, ", oh.bup); diff --git a/src/sort.c b/src/sort.c index 5911a20..4fdb4e0 100644 --- a/src/sort.c +++ b/src/sort.c @@ -252,7 +252,7 @@ comparer_t field_selector(char c) * \param right The right side of the merge sort. * \return Relevant for merge sort decision. */ -int merge(struct conf_t *state, struct range_t *restrict left, struct range_t *restrict right) +static int merge(struct conf_t *state, struct range_t *restrict left, struct range_t *restrict right) { struct output_sort *p; int ret; @@ -282,13 +282,12 @@ void mergesort_ranges(struct conf_t *state, struct range_t *restrict orig, unsig unsigned int left, i, u_right; int s_right; struct range_t hold; + /* Merge sort split size */ + static const unsigned int MIN_MERGE_SIZE = 8; if (temp == NULL) temp = xmalloc(sizeof(struct range_t) * size); - /* Merge sort split size */ - static const unsigned int MIN_MERGE_SIZE = 8; - if (size < MIN_MERGE_SIZE) { for (left = 0; left < size; left++) { hold = *(orig + left);