implement proc_modules for self process

This commit is contained in:
Doug MacEachern 2004-07-08 03:01:43 +00:00
parent 49782b4d05
commit a0f68ed2a7
1 changed files with 47 additions and 1 deletions

View File

@ -29,6 +29,8 @@
#include "user_v5.h" #include "user_v5.h"
#include "utmp_v5.h" #include "utmp_v5.h"
#include <sys/ldr.h>
#define FIXED_TO_DOUBLE(x) (((double)x) / 65536.0) #define FIXED_TO_DOUBLE(x) (((double)x) / 65536.0)
/* these offsets wont change so just lookup them up during open */ /* 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; 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, int sigar_proc_modules_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_modules_t *procmods) 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) int sigar_os_fs_type_get(sigar_file_system_t *fsp)