diff --git a/src/os/solaris/solaris_sigar.c b/src/os/solaris/solaris_sigar.c index dd6bd4ed..828ad737 100644 --- a/src/os/solaris/solaris_sigar.c +++ b/src/os/solaris/solaris_sigar.c @@ -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,