Merge branch 'collectd-5.5' into collectd-5.6
[collectd.git] / src / zone.c
index 15eae6a..d9e46f5 100644 (file)
 #endif
 
 #include "collectd.h"
+
 #include "common.h"
 #include "plugin.h"
 
-#include <sys/types.h>
-#include <sys/vm_usage.h>
 #include <procfs.h>
 #include <zone.h>
 
@@ -49,20 +48,12 @@ typedef struct zone_stats {
        ushort_t      pctmem;
 } zone_stats_t;
 
-static long pagesize;
-
-static int zone_init (void)
-{
-       pagesize = sysconf(_SC_PAGESIZE);
-       return (0);
-}
-
 static int
-zone_compare(const zoneid_t *a, const zoneid_t *b)
+zone_compare(const void *a, const void *b)
 {
-       if (*a == *b)
+       if (*(const zoneid_t *)a == *(const zoneid_t *)b)
                return(0);
-       if (*a < *b)
+       if (*(const zoneid_t *)a < *(const zoneid_t *)b)
                return(-1);
        return(1);
 }
@@ -115,12 +106,13 @@ zone_find_stats(c_avl_tree_t *tree, zoneid_t zoneid)
        zoneid_t     *key = NULL;
 
        if (c_avl_get(tree, (void **)&zoneid, (void **)&ret)) {
-               if (!(ret = malloc(sizeof(zone_stats_t)))) {
+               if (!(ret = malloc(sizeof(*ret)))) {
                        WARNING("zone plugin: no memory");
                        return(NULL);
                }
-               if (!(key = malloc(sizeof(zoneid_t)))) {
+               if (!(key = malloc(sizeof(*key)))) {
                        WARNING("zone plugin: no memory");
+                       free(ret);
                        return(NULL);
                }
                *key = zoneid;
@@ -142,7 +134,7 @@ zone_submit_values(c_avl_tree_t *tree)
        while (c_avl_pick (tree, (void **)&zoneid, (void **)&stats) == 0)
        {
                if (getzonenamebyid(*zoneid, zonename, sizeof( zonename )) == -1) {
-                       WARNING("zone plugin: error retreiving zonename");
+                       WARNING("zone plugin: error retrieving zonename");
                } else {
                        zone_submit_value(zonename, (gauge_t)FRC2PCT(stats->pctcpu));
                }
@@ -161,7 +153,7 @@ zone_scandir(DIR *procdir)
        c_avl_tree_t *tree;
        zone_stats_t *stats;
 
-       if (!(tree=c_avl_create((void *) zone_compare))) {
+       if (!(tree=c_avl_create(zone_compare))) {
                WARNING("zone plugin: Failed to create tree");
                return(NULL);
        }
@@ -209,6 +201,5 @@ static int zone_read (void)
 
 void module_register (void)
 {
-       plugin_register_init ("zone", zone_init);
        plugin_register_read ("zone", zone_read);
 } /* void module_register */