Merge pull request #795 from vincentbernat/fix/libstatgrab
authorPierre-Yves Ritschard <pyr@spootnik.org>
Sat, 15 Nov 2014 09:51:49 +0000 (10:51 +0100)
committerPierre-Yves Ritschard <pyr@spootnik.org>
Sat, 15 Nov 2014 09:51:49 +0000 (10:51 +0100)
libstatgrab: fix sg_init() invocation for libstatgrab >= 0.9

configure.ac
src/daemon/collectd.c
src/disk.c
src/users.c

index b6f35c8..13577c9 100644 (file)
@@ -4077,6 +4077,68 @@ then
   LDFLAGS="$SAVE_LDFLAGS"
 fi
 
+if test "x$with_libstatgrab" = "xyes"
+then
+  SAVE_CFLAGS="$CFLAGS"
+  SAVE_LDFLAGS="$LDFLAGS"
+
+  CFLAGS="$CFLAGS $with_libstatgrab_cflags"
+  LDFLAGS="$LDFLAGS $with_libstatgrab_ldflags"
+
+  AC_CACHE_CHECK([if sg_init() requires an argument],
+          [c_cv_have_libstatgrab_init_arg],
+          AC_LINK_IFELSE([AC_LANG_PROGRAM(
+[[[
+#include <stdio.h>
+#include <statgrab.h>
+]]],
+[[[
+      if (sg_init()) return 0;
+]]]
+    )],
+    [c_cv_have_libstatgrab_init_arg="no"],
+    [c_cv_have_libstatgrab_init_arg="yes"]
+          )
+  )
+
+  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 <stdio.h>
+#include <statgrab.h>
+]]],
+[[[
+      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"]
+          )
+  )
+
+  AC_CACHE_CHECK([if sg_disk_io_stats() uses size_t],
+          [c_cv_have_libstatgrab_get_disk_io_stats_sizet],
+          AC_LINK_IFELSE([AC_LANG_PROGRAM(
+[[[
+#include <stdio.h>
+#include <statgrab.h>
+]]],
+[[[
+      sg_disk_io_stats *(*ptr) (size_t *);
+      ptr = sg_get_disk_io_stats;
+      if (ptr != NULL) return 0;
+]]]
+    )],
+    [c_cv_have_libstatgrab_get_disk_io_stats_sizet="yes"],
+    [c_cv_have_libstatgrab_get_disk_io_stats_sizet="no"]
+          )
+  )
+
+  CFLAGS="$SAVE_CFLAGS"
+  LDFLAGS="$SAVE_LDFLAGS"
+fi
+
 AM_CONDITIONAL(BUILD_WITH_LIBSTATGRAB, test "x$with_libstatgrab" = "xyes")
 if test "x$with_libstatgrab" = "xyes"
 then
@@ -4085,6 +4147,18 @@ then
   BUILD_WITH_LIBSTATGRAB_LDFLAGS="$with_libstatgrab_ldflags"
   AC_SUBST(BUILD_WITH_LIBSTATGRAB_CFLAGS)
   AC_SUBST(BUILD_WITH_LIBSTATGRAB_LDFLAGS)
+  if test "x$c_cv_have_libstatgrab_init_arg" = "xyes"
+  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
+  if test "x$c_cv_have_libstatgrab_get_disk_io_stats_sizet" = "xyes"
+  then
+        AC_DEFINE(HAVE_LIBSTATGRAB_GET_DISK_IO_STATS_SIZET, 1, [Define to 1 if sg_get_disk_io_stats does require pointer to size_t as an argument])
+  fi
 fi
 # }}}
 
index eb5404f..9cba913 100644 (file)
@@ -308,7 +308,11 @@ static int do_init (void)
 #endif
 
 #if HAVE_LIBSTATGRAB
-       if (sg_init ())
+       if (sg_init (
+# if HAVE_LIBSTATGRAB_INIT_ARG
+                   0
+# endif
+                   ))
        {
                ERROR ("sg_init: %s", sg_str_error (sg_get_error ()));
                return (-1);
index e84e835..51fbc02 100644 (file)
@@ -831,7 +831,12 @@ static int disk_read (void)
 
 #elif defined(HAVE_LIBSTATGRAB)
        sg_disk_io_stats *ds;
-       int disks, counter;
+# if HAVE_LIBSTATGRAB_GET_DISK_IO_STATS_SIZET
+       size_t disks;
+# else
+       int disks;
+#endif
+       int counter;
        char name[DATA_MAX_NAME_LEN];
        
        if ((ds = sg_get_disk_io_stats(&disks)) == NULL)
index 781e778..40ffece 100644 (file)
@@ -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