From c963d35fb88b7db81fcf6e3db51313d9002e17b4 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Thu, 13 Nov 2014 17:57:46 +0100 Subject: [PATCH] libstatgrab: fix sg_get_disk_io_stats() invocation for libstatgrab >= 0.9 In those versions, `sg_get_disk_io_stats()` need to be invoked a pointer to size_t instead of pointer to int. Such a requirement is detected at configure-time. Fixes: #445 --- configure.ac | 22 ++++++++++++++++++++++ src/disk.c | 7 ++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index f1873dee..73410500 100644 --- a/configure.ac +++ b/configure.ac @@ -4117,6 +4117,24 @@ then ) ) + 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 +#include +]]], +[[[ + 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 @@ -4137,6 +4155,10 @@ then 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 # }}} diff --git a/src/disk.c b/src/disk.c index e84e8355..51fbc025 100644 --- a/src/disk.c +++ b/src/disk.c @@ -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) -- 2.11.0