pullout some dlinfo code from proc_modules to be reused

This commit is contained in:
Doug MacEachern 2004-07-30 02:27:58 +00:00
parent 19e7aa64a5
commit 5213a822f6
1 changed files with 35 additions and 15 deletions

View File

@ -483,6 +483,37 @@ static int sigar_pgrab(sigar_t *sigar, sigar_pid_t pid,
return SIGAR_OK;
}
static int sigar_dlinfo_get(sigar_t *sigar, const char *func,
void **handle, Link_map **map)
{
Dl_info dli;
if (!dladdr((void *)((uintptr_t)sigar_dlinfo_get), &dli)) {
sigar_log_printf(sigar, SIGAR_LOG_ERROR,
"[%s] dladdr(%s) = %s",
func, SIGAR_FUNC, dlerror());
return ESRCH;
}
if (!(*handle = dlopen(dli.dli_fname, RTLD_LAZY))) {
sigar_log_printf(sigar, SIGAR_LOG_ERROR,
"[%s] dlopen(%s) = %s",
func, dli.dli_fname, dlerror());
return ESRCH;
}
dlinfo(*handle, RTLD_DI_LINKMAP, map);
if (!map) {
sigar_log_printf(sigar, SIGAR_LOG_ERROR,
"[%s] dlinfo = %s",
func, dlerror());
return ESRCH;
}
return SIGAR_OK;
}
int sigar_proc_list_get(sigar_t *sigar,
sigar_proc_list_t *proclist)
{
@ -897,26 +928,15 @@ static int sigar_pgrab_modules(sigar_t *sigar, sigar_pid_t pid,
static int sigar_dlinfo_modules(sigar_t *sigar, sigar_proc_modules_t *procmods)
{
int status;
void *handle;
Dl_info dli;
Link_map *map;
if (!dladdr((void *)((uintptr_t)sigar_dlinfo_modules), &dli)) {
sigar_log_printf(sigar, SIGAR_LOG_ERROR,
"[%s] dladdr(%s) = %s",
SIGAR_FUNC, SIGAR_FUNC, dlerror());
return ESRCH;
status = sigar_dlinfo_get(sigar, SIGAR_FUNC, &handle, &map);
if (status != SIGAR_OK) {
return status;
}
if (!(handle = dlopen(dli.dli_fname, RTLD_LAZY))) {
sigar_log_printf(sigar, SIGAR_LOG_ERROR,
"[%s] dlopen(%s) = %s",
SIGAR_FUNC, dli.dli_fname, dlerror());
return ESRCH;
}
dlinfo(handle, RTLD_DI_LINKMAP, &map);
do {
int status =
procmods->module_getter(procmods->data,