From 7768626c4f446baa3ca777459570b851dfd4c6d9 Mon Sep 17 00:00:00 2001 From: Dagobert Michelsen Date: Thu, 28 May 2015 13:06:04 +0200 Subject: [PATCH] Use ZONENAME_MAX and handle errors returned by getzonenamebyid() --- src/zone.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/zone.c b/src/zone.c index 1781775f..325d5567 100644 --- a/src/zone.c +++ b/src/zone.c @@ -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); } -- 2.30.2