Merge branch 'collectd-5.8'
[collectd.git] / src / disk.c
index 41aacaa..e73a5c0 100644 (file)
@@ -23,9 +23,9 @@
 
 #include "collectd.h"
 
-#include "common.h"
 #include "plugin.h"
-#include "utils_ignorelist.h"
+#include "utils/common/common.h"
+#include "utils/ignorelist/ignorelist.h"
 
 #if HAVE_MACH_MACH_TYPES_H
 #include <mach/mach_types.h>
@@ -701,7 +701,7 @@ static int disk_read(void) {
         break;
 
     if (ds == NULL) {
-      if ((ds = (diskstats_t *)calloc(1, sizeof(diskstats_t))) == NULL)
+      if ((ds = calloc(1, sizeof(*ds))) == NULL)
         continue;
 
       if ((ds->name = strdup(disk_name)) == NULL) {
@@ -820,7 +820,7 @@ static int disk_read(void) {
       ds->poll_count = poll_count;
       continue;
     }
-    ds->poll_count++;
+    ds->poll_count = poll_count;
 
     if ((read_ops == 0) && (write_ops == 0)) {
       DEBUG("disk plugin: ((read_ops == 0) && "
@@ -884,14 +884,12 @@ static int disk_read(void) {
 
     /* Disk is missing, remove it */
     diskstats_t *missing_ds = ds;
-    if (pre_ds == disklist) {
-      disklist = ds->next;
-      ds = disklist;
-      pre_ds = ds;
+    if (ds == disklist) {
+      pre_ds = disklist = ds->next;
     } else {
       pre_ds->next = ds->next;
-      ds = ds->next;
     }
+    ds = ds->next;
 
     DEBUG("disk plugin: Disk %s disappeared.", missing_ds->name);
     free(missing_ds->name);
@@ -991,9 +989,8 @@ static int disk_read(void) {
   }
 
   if (numdisk != pnumdisk || stat_disk == NULL) {
-    if (stat_disk != NULL)
-      free(stat_disk);
-    stat_disk = (perfstat_disk_t *)calloc(numdisk, sizeof(perfstat_disk_t));
+    free(stat_disk);
+    stat_disk = calloc(numdisk, sizeof(*stat_disk));
   }
   pnumdisk = numdisk;