move sigar_get_self_path to sigar_util

This commit is contained in:
Doug MacEachern 2005-12-14 18:40:13 +00:00
parent dc3eceb517
commit 5fc7cc7134
2 changed files with 48 additions and 0 deletions

View File

@ -81,6 +81,8 @@ double sigar_file_system_usage_calc_used(sigar_t *sigar,
void sigar_cpu_model_adjust(sigar_t *sigar, sigar_cpu_info_t *info); void sigar_cpu_model_adjust(sigar_t *sigar, sigar_cpu_info_t *info);
char *sigar_get_self_path(sigar_t *sigar);
typedef struct sigar_cache_entry_t sigar_cache_entry_t; typedef struct sigar_cache_entry_t sigar_cache_entry_t;
struct sigar_cache_entry_t { struct sigar_cache_entry_t {

View File

@ -510,6 +510,52 @@ SIGAR_DECLARE(int) sigar_nfs_ping(char *host)
#define vsnprintf _vsnprintf #define vsnprintf _vsnprintf
#endif #endif
static int proc_module_get_self(void *data, char *name, int len)
{
sigar_t *sigar = (sigar_t *)data;
char *ptr = rindex(name, '/');
if (!ptr) {
return SIGAR_OK;
}
if (strnEQ(ptr+1, "libsigar-", 9)) {
*ptr = '\0'; /* chop libsigar-powerpc-ibm-aix-4.3.x.so */
sigar->self_path = sigar_strdup(name);
if (SIGAR_LOG_IS_DEBUG(sigar)) {
sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
"detected sigar-lib='%s'",
sigar->self_path);
}
return !SIGAR_OK; /* break loop */
}
return SIGAR_OK;
}
char *sigar_get_self_path(sigar_t *sigar)
{
if (!sigar->self_path) {
sigar_proc_modules_t procmods;
procmods.module_getter = proc_module_get_self;
procmods.data = sigar;
sigar_proc_modules_get(sigar,
sigar_pid_get(sigar),
&procmods);
if (!sigar->self_path) {
/* dont try again */
sigar->self_path = sigar_strdup(".");
}
}
return sigar->self_path;
}
SIGAR_DECLARE(void) sigar_log_printf(sigar_t *sigar, int level, SIGAR_DECLARE(void) sigar_log_printf(sigar_t *sigar, int level,
const char *format, ...) const char *format, ...)
{ {