From dc3eceb5171044390b7fa60fe0bd49bbfc5fd1a0 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 14 Dec 2005 18:35:19 +0000 Subject: [PATCH] move self_path to the base sigar_t --- include/sigar_private.h | 3 ++- src/os/aix/aix_sigar.c | 10 ++++------ src/os/aix/sigar_os.h | 1 - src/sigar.c | 5 ++++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/sigar_private.h b/include/sigar_private.h index 48c76c83..f74f235f 100644 --- a/include/sigar_private.h +++ b/include/sigar_private.h @@ -36,7 +36,8 @@ sigar_pid_t pid; \ char errbuf[256]; \ char *ifconf_buf; \ - int ifconf_len + int ifconf_len; \ + char *self_path #if defined(WIN32) # define SIGAR_INLINE __inline diff --git a/src/os/aix/aix_sigar.c b/src/os/aix/aix_sigar.c index cf70ca47..05ec2069 100644 --- a/src/os/aix/aix_sigar.c +++ b/src/os/aix/aix_sigar.c @@ -164,8 +164,6 @@ int sigar_os_open(sigar_t **sigar) (*sigar)->model[0] = '\0'; - (*sigar)->self_path[0] = '\0'; - uname(&name); (*sigar)->aix_version = atoi(name.version); @@ -231,7 +229,7 @@ static int proc_module_get_self(void *data, char *name, int len) if (strnEQ(ptr+1, "libsigar-", 9)) { *ptr = '\0'; /* chop libsigar-powerpc-ibm-aix-4.3.x.so */ - SIGAR_SSTRCPY(sigar->self_path, name); + sigar->self_path = sigar_strdup(name); if (SIGAR_LOG_IS_DEBUG(sigar)) { sigar_log_printf(sigar, SIGAR_LOG_DEBUG, @@ -247,7 +245,7 @@ static int proc_module_get_self(void *data, char *name, int len) static char *sigar_get_self_path(sigar_t *sigar) { - if (sigar->self_path[0] == '\0') { + if (!sigar->self_path) { sigar_proc_modules_t procmods; procmods.module_getter = proc_module_get_self; procmods.data = sigar; @@ -255,9 +253,9 @@ static char *sigar_get_self_path(sigar_t *sigar) sigar_proc_modules_get(sigar, sigar_pid_get(sigar), &procmods); - if (sigar->self_path[0] == '\0') { + if (!sigar->self_path) { /* dont try again */ - SIGAR_SSTRCPY(sigar->self_path, "."); + sigar->self_path = sigar_strdup("."); } } diff --git a/src/os/aix/sigar_os.h b/src/os/aix/sigar_os.h index 803e1690..294997ad 100644 --- a/src/os/aix/sigar_os.h +++ b/src/os/aix/sigar_os.h @@ -72,7 +72,6 @@ struct sigar_t { int cpuinfo_size; int cpu_mhz; char model[128]; - char self_path[SIGAR_PATH_MAX]; /* path to where libsigar.so lives */ int aix_version; int thrusage; sigar_cache_t *diskmap; diff --git a/src/sigar.c b/src/sigar.c index 9614165a..e7a8a7cf 100644 --- a/src/sigar.c +++ b/src/sigar.c @@ -21,6 +21,7 @@ SIGAR_DECLARE(int) sigar_open(sigar_t **sigar) (*sigar)->log_level = -1; /* log nothing by default */ (*sigar)->log_impl = NULL; (*sigar)->log_data = NULL; + (*sigar)->self_path = NULL; } return status; @@ -31,7 +32,9 @@ SIGAR_DECLARE(int) sigar_close(sigar_t *sigar) if (sigar->ifconf_buf) { free(sigar->ifconf_buf); } - + if (sigar->self_path) { + free(sigar->self_path); + } return sigar_os_close(sigar); }