From fb475be338cac6a25e296bfec5f81dc8f691b832 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 9 Dec 2005 19:24:40 +0000 Subject: [PATCH] always use sigar_kstat_update rather than kstat_chain_update directly --- src/os/solaris/kstats.c | 24 +++++++++++++++++++++++- src/os/solaris/sigar_os.h | 2 ++ src/os/solaris/solaris_sigar.c | 20 ++++---------------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/os/solaris/kstats.c b/src/os/solaris/kstats.c index 941a37d9..8dab8591 100644 --- a/src/os/solaris/kstats.c +++ b/src/os/solaris/kstats.c @@ -16,7 +16,7 @@ int sigar_get_multi_kstats(sigar_t *sigar, name += kl->nlen; /* e.g. "hme0" + 3 */ dev = atoi(name); - if ((kl->num == 0) || (kstat_chain_update(kc) > 0)) { + if ((kl->num == 0) || (sigar_kstat_update(sigar) > 0)) { while ((ksp = kstat_lookup(kc, kl->name, i, NULL))) { if (i+1 > kl->num) { kl->num = i+1; @@ -111,6 +111,28 @@ int sigar_get_kstats(sigar_t *sigar) return SIGAR_OK; } +SIGAR_INLINE kid_t sigar_kstat_update(sigar_t *sigar) +{ + kid_t id = kstat_chain_update(sigar->kc); + + switch (id) { + case -1: + sigar_log_printf(sigar, SIGAR_LOG_ERROR, + "kstat_chain_update error: %s", + sigar_strerror(sigar, errno)); + break; + case 0: + break; + default: + sigar_get_kstats(sigar); + sigar_log(sigar, SIGAR_LOG_DEBUG, + "kstat chain updated"); + break; + } + + return id; +} + /* * bincompat is not possible with certain kstat data structures between * solaris 2.6, 2.7, 2.8, etc. alternative is to use kstat_data_lookup() diff --git a/src/os/solaris/sigar_os.h b/src/os/solaris/sigar_os.h index ed4aa32c..51775bb7 100644 --- a/src/os/solaris/sigar_os.h +++ b/src/os/solaris/sigar_os.h @@ -33,6 +33,8 @@ typedef struct { int nlen; } kstat_list_t; +SIGAR_INLINE kid_t sigar_kstat_update(sigar_t *sigar); + int sigar_get_kstats(sigar_t *sigar); int sigar_get_multi_kstats(sigar_t *sigar, diff --git a/src/os/solaris/solaris_sigar.c b/src/os/solaris/solaris_sigar.c index f20197d0..6325846f 100644 --- a/src/os/solaris/solaris_sigar.c +++ b/src/os/solaris/solaris_sigar.c @@ -154,20 +154,6 @@ char *sigar_os_error_string(sigar_t *sigar, int err) } } -static SIGAR_INLINE int sigar_kstat_update(sigar_t *sigar) -{ - switch (kstat_chain_update(sigar->kc)) { - case 0: - break; - case -1: - return -1; /* shouldn't happen */ - default: - sigar_get_kstats(sigar); - } - - return SIGAR_OK; -} - #define KPAGE_SHIFT(v) \ ((v) << sigar->pagesize) @@ -1368,7 +1354,8 @@ static int get_fs_kstat(sigar_t *sigar, kstat_t *ksp, *first; char *ptr; - kstat_chain_update(sigar->kc); + sigar_kstat_update(sigar); + first = ksp = kstat_lookup(sigar->kc, fsk->module, fsk->instance, NULL); @@ -1980,7 +1967,8 @@ static int sigar_net_ifstat_get_any(sigar_t *sigar, const char *name, char dev[64], *ptr=dev; int num; - kstat_chain_update(kc); + sigar_kstat_update(sigar); + strncpy(dev, name, sizeof(dev)-1); dev[sizeof(dev)-1] = '\0';