From 20f9591f4a37e0cf9bd7f8d9206c4c51a0617a63 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Fri, 13 Mar 2009 18:23:20 +0100 Subject: [PATCH] src/common.c, memory plugin: Fix a potential problem under Solaris. When the kstat chain has been updated (and init is called again), get_kstat should overwrite the existing kstat pointer thingy. --- src/common.c | 26 +++++++++++++------------- src/memory.c | 5 ++++- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/common.c b/src/common.c index 182f923d..122f9624 100644 --- a/src/common.c +++ b/src/common.c @@ -495,26 +495,26 @@ int check_create_dir (const char *file_orig) int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name) { char ident[128]; + + *ksp_ptr = NULL; if (kc == NULL) return (-1); ssnprintf (ident, sizeof (ident), "%s,%i,%s", module, instance, name); + *ksp_ptr = kstat_lookup (kc, module, instance, name); if (*ksp_ptr == NULL) { - if ((*ksp_ptr = kstat_lookup (kc, module, instance, name)) == NULL) - { - ERROR ("Cound not find kstat %s", ident); - return (-1); - } + ERROR ("get_kstat: Cound not find kstat %s", ident); + return (-1); + } - if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED) - { - WARNING ("kstat %s has wrong type", ident); - *ksp_ptr = NULL; - return (-1); - } + if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED) + { + ERROR ("get_kstat: kstat %s has wrong type", ident); + *ksp_ptr = NULL; + return (-1); } #ifdef assert @@ -524,13 +524,13 @@ int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name) if (kstat_read (kc, *ksp_ptr, NULL) == -1) { - WARNING ("kstat %s could not be read", ident); + ERROR ("get_kstat: kstat %s could not be read", ident); return (-1); } if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED) { - WARNING ("kstat %s has wrong type", ident); + ERROR ("get_kstat: kstat %s has wrong type", ident); return (-1); } diff --git a/src/memory.c b/src/memory.c index c31b30ef..63c3e6ac 100644 --- a/src/memory.c +++ b/src/memory.c @@ -92,8 +92,11 @@ static int memory_init (void) #elif defined(HAVE_LIBKSTAT) /* getpagesize(3C) tells me this does not fail.. */ pagesize = getpagesize (); - if (get_kstat (&ksp, "unix", 0, "system_pages")) + if (get_kstat (&ksp, "unix", 0, "system_pages") != 0) + { ksp = NULL; + return (-1); + } #endif /* HAVE_LIBKSTAT */ return (0); -- 2.11.0