Code

Use ZONENAME_MAX and handle errors returned by getzonenamebyid()
authorDagobert Michelsen <dam@opencsw.org>
Thu, 28 May 2015 11:06:04 +0000 (13:06 +0200)
committerDagobert Michelsen <dam@opencsw.org>
Thu, 28 May 2015 11:06:04 +0000 (13:06 +0200)
src/zone.c

index 1781775ff90b68a5a4abba5af4792ea086175b40..325d556701563910099a7ff662e609c98abb937f 100644 (file)
@@ -33,7 +33,6 @@
 #include "utils_avltree.h"
 
 #define        MAX_PROCFS_PATH 40
-#define MAX_ZONE_NAME 20
 #define FRC2PCT(pp)(((float)(pp))/0x8000*100)
 
 typedef struct zone_stats {
@@ -119,14 +118,17 @@ zone_find_stats(c_avl_tree_t *tree, zoneid_t zoneid)
 static void
 zone_submit_values(c_avl_tree_t *tree)
 {
-       char          zonename[MAX_ZONE_NAME];
+       char          zonename[ZONENAME_MAX];
        zoneid_t     *zoneid = NULL;
        zone_stats_t *stats  = NULL;
 
        while (c_avl_pick (tree, (void **)&zoneid, (void **)&stats) == 0)
        {
-               getzonenamebyid(*zoneid, zonename, MAX_ZONE_NAME-1);
-               zone_submit_value(zonename, (gauge_t)FRC2PCT(stats->pctcpu));
+               if (getzonenamebyid(*zoneid, zonename, sizeof( zonename )) == -1) {
+                       WARNING("zone plugin: error retreiving zonename");
+               } else {
+                       zone_submit_value(zonename, (gauge_t)FRC2PCT(stats->pctcpu));
+               }
                free(stats);
                free(zoneid);
        }