function to get the directory where libsigar.so lives

This commit is contained in:
Doug MacEachern 2004-07-08 03:29:59 +00:00
parent a0f68ed2a7
commit 036f8e7789
1 changed files with 41 additions and 0 deletions

View File

@ -121,6 +121,8 @@ int sigar_os_open(sigar_t **sigar)
(*sigar)->model[0] = '\0';
(*sigar)->self_path[0] = '\0';
return SIGAR_OK;
}
@ -831,6 +833,45 @@ int sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
return SIGAR_ENOTIMPL;
}
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_SSTRCPY(sigar->self_path, name);
return !SIGAR_OK; /* break loop */
}
return SIGAR_OK;
}
static char *sigar_get_self_path(sigar_t *sigar)
{
if (sigar->self_path[0] == '\0') {
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[0] == '\0') {
/* dont try again */
SIGAR_SSTRCPY(sigar->self_path, "unknown");
}
}
return sigar->self_path;
}
static int sigar_proc_modules_local_get(sigar_t *sigar,
sigar_proc_modules_t *procmods)
{