Merge branch 'collectd-5.7' into collectd-5.8
[collectd.git] / src / disk.c
index fbea064..2234c02 100644 (file)
@@ -120,6 +120,9 @@ static struct gmesh geom_tree;
 /* #endif KERNEL_FREEBSD */
 
 #elif HAVE_LIBKSTAT
+#if HAVE_KSTAT_H
+#include <kstat.h>
+#endif
 #define MAX_NUMDISK 1024
 extern kstat_ctl_t *kc;
 static kstat_t *ksp[MAX_NUMDISK];
@@ -139,7 +142,7 @@ static int pnumdisk;
 #error "No applicable input method."
 #endif
 
-#if HAVE_UDEV_H
+#if HAVE_LIBUDEV_H
 #include <libudev.h>
 
 static char *conf_udev_name_attr = NULL;
@@ -173,7 +176,7 @@ static int disk_config(const char *key, const char *value) {
             "on Mach / Mac OS X and will be ignored.");
 #endif
   } else if (strcasecmp("UdevNameAttr", key) == 0) {
-#if HAVE_UDEV_H
+#if HAVE_LIBUDEV_H
     if (conf_udev_name_attr != NULL) {
       free(conf_udev_name_attr);
       conf_udev_name_attr = NULL;
@@ -209,7 +212,7 @@ static int disk_init(void) {
 /* #endif HAVE_IOKIT_IOKITLIB_H */
 
 #elif KERNEL_LINUX
-#if HAVE_UDEV_H
+#if HAVE_LIBUDEV_H
   if (conf_udev_name_attr != NULL) {
     handle_udev = udev_new();
     if (handle_udev == NULL) {
@@ -217,7 +220,7 @@ static int disk_init(void) {
       return -1;
     }
   }
-#endif /* HAVE_UDEV_H */
+#endif /* HAVE_LIBUDEV_H */
 /* #endif KERNEL_LINUX */
 
 #elif KERNEL_FREEBSD
@@ -260,10 +263,10 @@ static int disk_init(void) {
 
 static int disk_shutdown(void) {
 #if KERNEL_LINUX
-#if HAVE_UDEV_H
+#if HAVE_LIBUDEV_H
   if (handle_udev != NULL)
     udev_unref(handle_udev);
-#endif /* HAVE_UDEV_H */
+#endif /* HAVE_LIBUDEV_H */
 #endif /* KERNEL_LINUX */
   return 0;
 } /* int disk_shutdown */
@@ -325,7 +328,7 @@ static counter_t disk_calc_time_incr(counter_t delta_time,
 }
 #endif
 
-#if HAVE_UDEV_H
+#if HAVE_LIBUDEV_H
 /**
  * Attempt to provide an rename disk instance from an assigned udev attribute.
  *
@@ -405,8 +408,8 @@ static int disk_read(void) {
 
   /* Get the list of all disk objects. */
   if (IOServiceGetMatchingServices(
-                                   io_master_port, IOServiceMatching(kIOBlockStorageDriverClass),
-                                   &disk_list) != kIOReturnSuccess) {
+          io_master_port, IOServiceMatching(kIOBlockStorageDriverClass),
+          &disk_list) != kIOReturnSuccess) {
     ERROR("disk plugin: IOServiceGetMatchingServices failed.");
     return -1;
   }
@@ -490,8 +493,7 @@ static int disk_read(void) {
         sstrncpy(disk_name, props_disk_name_bsd, sizeof(disk_name));
       else {
         ERROR("disk plugin: can't find bsd disk name.");
-        snprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major,
-                  disk_minor);
+        snprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, disk_minor);
       }
     } else
       snprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, disk_minor);
@@ -695,7 +697,9 @@ static int disk_read(void) {
 
     numfields = strsplit(buffer, fields, 32);
 
-    if ((numfields != (14 + fieldshift)) && (numfields != 7))
+    /* need either 7 fields (partition)
+     * or at least 14 fields (15 on Linux 2.4) */
+    if ((numfields != 7) && (numfields < (14 + fieldshift)))
       continue;
 
     minor = atoll(fields[1]);
@@ -729,7 +733,8 @@ static int disk_read(void) {
       read_sectors = atoll(fields[4]);
       write_ops = atoll(fields[5]);
       write_sectors = atoll(fields[6]);
-    } else if (numfields == (14 + fieldshift)) {
+    } else {
+      assert(numfields >= (14 + fieldshift));
       read_ops = atoll(fields[3 + fieldshift]);
       write_ops = atoll(fields[7 + fieldshift]);
 
@@ -748,9 +753,6 @@ static int disk_read(void) {
         io_time = atof(fields[12 + fieldshift]);
         weighted_time = atof(fields[13 + fieldshift]);
       }
-    } else {
-      DEBUG("numfields = %i; => unknown file format.", numfields);
-      continue;
     }
 
     {
@@ -842,7 +844,7 @@ static int disk_read(void) {
 
     output_name = disk_name;
 
-#if HAVE_UDEV_H
+#if HAVE_LIBUDEV_H
     char *alt_name = NULL;
     if (conf_udev_name_attr != NULL) {
       alt_name =
@@ -853,7 +855,7 @@ static int disk_read(void) {
 #endif
 
     if (ignorelist_match(ignorelist, output_name) != 0) {
-#if HAVE_UDEV_H
+#if HAVE_LIBUDEV_H
       /* release udev-based alternate name, if allocated */
       sfree(alt_name);
 #endif
@@ -879,7 +881,7 @@ static int disk_read(void) {
         submit_io_time(output_name, io_time, weighted_time);
     } /* if (is_disk) */
 
-#if HAVE_UDEV_H
+#if HAVE_LIBUDEV_H
     /* release udev-based alternate name, if allocated */
     sfree(alt_name);
 #endif