From 1df568b4efae6cc07f67f711d1128c26f3bfefbf Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Mon, 19 Jul 2004 21:33:18 +0000 Subject: [PATCH] proper return value check for perfstat functions --- src/os/aix/aix_sigar.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/os/aix/aix_sigar.c b/src/os/aix/aix_sigar.c index f6183374..fea5c125 100644 --- a/src/os/aix/aix_sigar.c +++ b/src/os/aix/aix_sigar.c @@ -568,7 +568,7 @@ int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu) if (sigar_perfstat_init(sigar) == SIGAR_OK) { sigar_log(sigar, SIGAR_LOG_DEBUG, "[cpu] using libperfstat"); - if (sigar->perfstat.cpu_total(&cpu_data, sizeof(cpu_data))) { + if (sigar->perfstat.cpu_total(&cpu_data, sizeof(cpu_data)) == 1) { cpu->user = cpu_data.user; cpu->nice = -1; /* N/A */ cpu->sys = cpu_data.sys; @@ -691,7 +691,7 @@ static int sigar_cpu_list_get_pstat(sigar_t *sigar, sigar_cpu_list_t *cpulist) i, id.name); } - if (sigar->perfstat.cpu(&id, &data, sizeof(data), 1)) { + if (sigar->perfstat.cpu(&id, &data, sizeof(data), 1) == 1) { cpu->user = data.user; cpu->nice = -1; /* N/A */ cpu->sys = data.sys; @@ -700,8 +700,8 @@ static int sigar_cpu_list_get_pstat(sigar_t *sigar, sigar_cpu_list_t *cpulist) } else { sigar_log_printf(sigar, SIGAR_LOG_ERROR, - "cpu%d perfstat_cpu(%s) failed", - i, id.name); + "cpu%d perfstat_cpu(%s) failed: %s", + i, id.name, sigar_strerror(sigar, errno)); SIGAR_ZERO(cpu); } } @@ -813,12 +813,17 @@ int sigar_loadavg_get(sigar_t *sigar, sigar_log(sigar, SIGAR_LOG_DEBUG, "[loadavg] using libperfstat"); - if (sigar->perfstat.cpu_total(&cpu_data, sizeof(cpu_data))) { + if (sigar->perfstat.cpu_total(&cpu_data, sizeof(cpu_data)) == 1) { for (i=0; i<3; i++) { loadavg->loadavg[i] = FIXED_TO_DOUBLE(cpu_data.loadavg[i]); } return SIGAR_OK; } + else { + sigar_log_printf(sigar, SIGAR_LOG_ERROR, + "perfstat_cpu_total failed: %s", + sigar_strerror(sigar, errno)); + } } sigar_log(sigar, SIGAR_LOG_DEBUG, @@ -1404,10 +1409,15 @@ static int sigar_get_cpu_mhz_perfstat(sigar_t *sigar) perfstat_cpu_total_t data; if (sigar_perfstat_init(sigar) == SIGAR_OK) { - if (sigar->perfstat.cpu_total(&data, sizeof(data))) { + if (sigar->perfstat.cpu_total(&data, sizeof(data)) == 1) { sigar->cpu_mhz = data.processorHZ / 1000000; return SIGAR_OK; } + else { + sigar_log_printf(sigar, SIGAR_LOG_ERROR, + "perfstat_cpu_total failed: %s", + sigar_strerror(sigar, errno)); + } } return ENOENT;