From: Vincent Bernat Date: Wed, 12 Nov 2014 12:19:05 +0000 (+0100) Subject: libstatgrab: fix sg_get_user_stats() invocation for libstatgrab >= 0.9 X-Git-Tag: collectd-5.5.0~147^2~3 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=2233e6a537fb0a197881a17779503b8279125381;p=collectd.git libstatgrab: fix sg_get_user_stats() invocation for libstatgrab >= 0.9 In those versions, `sg_get_user_stats()` need to be invoked with an additional argument. The need for such an argument is detected at configure-time. Fixes: #445 --- diff --git a/configure.ac b/configure.ac index 35f89464..f1873dee 100644 --- a/configure.ac +++ b/configure.ac @@ -4101,6 +4101,22 @@ then ) ) + AC_CACHE_CHECK([if sg_get_user_stats() requires an argument], + [c_cv_have_libstatgrab_get_user_stats_arg], + AC_LINK_IFELSE([AC_LANG_PROGRAM( +[[[ +#include +#include +]]], +[[[ + if (sg_get_user_stats()) return 0; +]]] + )], + [c_cv_have_libstatgrab_get_user_stats_arg="no"], + [c_cv_have_libstatgrab_get_user_stats_arg="yes"] + ) + ) + CFLAGS="$SAVE_CFLAGS" LDFLAGS="$SAVE_LDFLAGS" fi @@ -4117,6 +4133,10 @@ then then AC_DEFINE(HAVE_LIBSTATGRAB_INIT_ARG, 1, [Define to 1 if sg_init does require an argument]) fi + if test "x$c_cv_have_libstatgrab_get_user_stats_arg" = "xyes" + then + AC_DEFINE(HAVE_LIBSTATGRAB_GET_USER_STATS_ARG, 1, [Define to 1 if sg_get_user_stats does require an argument]) + fi fi # }}} diff --git a/src/users.c b/src/users.c index 781e7787..40ffece1 100644 --- a/src/users.c +++ b/src/users.c @@ -102,11 +102,21 @@ static int users_read (void) #elif HAVE_LIBSTATGRAB sg_user_stats *us; +# if HAVE_LIBSTATGRAB_GET_USER_STATS_ARG + size_t num_entries; + us = sg_get_user_stats (&num_entries); +# else us = sg_get_user_stats (); +# endif if (us == NULL) return (-1); - users_submit ((gauge_t) us->num_entries); + users_submit ((gauge_t) +# if HAVE_LIBSTATGRAB_GET_USER_STATS_ARG + num_entries); +# else + us->num_entries); +# endif /* #endif HAVE_LIBSTATGRAB */ #else