From a0f68ed2a74cc5337d6c07069bc83ea756e3d0c9 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Thu, 8 Jul 2004 03:01:43 +0000 Subject: [PATCH] implement proc_modules for self process --- src/os/aix/aix_sigar.c | 48 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/os/aix/aix_sigar.c b/src/os/aix/aix_sigar.c index c4486e71..64feb9c1 100644 --- a/src/os/aix/aix_sigar.c +++ b/src/os/aix/aix_sigar.c @@ -29,6 +29,8 @@ #include "user_v5.h" #include "utmp_v5.h" +#include + #define FIXED_TO_DOUBLE(x) (((double)x) / 65536.0) /* these offsets wont change so just lookup them up during open */ @@ -829,10 +831,54 @@ int sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid, return SIGAR_ENOTIMPL; } +static int sigar_proc_modules_local_get(sigar_t *sigar, + sigar_proc_modules_t *procmods) +{ + struct ld_info *info; + char *buffer; + int size = 2048, status; + unsigned int offset; + + buffer = malloc(size); + while ((loadquery(L_GETINFO, buffer, size) == -1) && + (errno == ENOMEM)) + { + size += 2048; + buffer = realloc(buffer, size); + } + + info = (struct ld_info *)buffer; + + do { + char *name = info->ldinfo_filename; + + status = + procmods->module_getter(procmods->data, name, strlen(name)); + + if (status != SIGAR_OK) { + /* not an error; just stop iterating */ + free(buffer); + return status; + } + + offset = info->ldinfo_next; + info = (struct ld_info *)((char*)info + offset); + } while(offset); + + free(buffer); + + return SIGAR_OK; +} + int sigar_proc_modules_get(sigar_t *sigar, sigar_pid_t pid, sigar_proc_modules_t *procmods) { - return SIGAR_ENOTIMPL; + if (pid == sigar_pid_get(sigar)) { + return sigar_proc_modules_local_get(sigar, procmods); + } + else { + return SIGAR_ENOTIMPL; + } } int sigar_os_fs_type_get(sigar_file_system_t *fsp)