fillin proc_exe.name

This commit is contained in:
Doug MacEachern 2004-07-30 02:15:05 +00:00
parent 4e3cdb949b
commit 19e7aa64a5
2 changed files with 25 additions and 3 deletions

View File

@ -162,12 +162,15 @@ enum {
typedef struct ps_prochandle * (*proc_grab_func_t)(pid_t, int, int *);
typedef void (*proc_free_func_t)(void *);
typedef void (*proc_free_func_t)(struct ps_prochandle *);
typedef void (*proc_objname_func_t)(void *, uintptr_t, const char *, size_t);
typedef void (*proc_objname_func_t)(struct ps_prochandle *,
uintptr_t, const char *, size_t);
typedef char * (*proc_dirname_func_t)(const char *, char *, size_t);
typedef char * (*proc_exename_func_t)(struct ps_prochandle *, char *, size_t);
struct sigar_t {
SIGAR_T_BASE;
@ -216,6 +219,7 @@ struct sigar_t {
proc_free_func_t pfree;
proc_objname_func_t pobjname;
proc_dirname_func_t pdirname;
proc_exename_func_t pexename;
};
#define kSTAT_uint(v, type) \

View File

@ -431,6 +431,7 @@ static int sigar_init_libproc(sigar_t *sigar)
sigar->pgrab = (proc_grab_func_t)dlsym(sigar->plib, "Pgrab");
sigar->pfree = (proc_free_func_t)dlsym(sigar->plib, "Pfree");
sigar->pobjname = (proc_objname_func_t)dlsym(sigar->plib, "Pobjname");
sigar->pexename = (proc_exename_func_t)dlsym(sigar->plib, "Pexecname");
sigar->pdirname = (proc_dirname_func_t)dlsym(sigar->plib, "proc_dirname");
CHECK_PSYM(pgrab);
@ -742,13 +743,30 @@ int sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
{
int status;
char buffer[BUFSIZ];
struct ps_prochandle *phandle;
if ((status = sigar_init_libproc(sigar)) != SIGAR_OK) {
return status;
}
procexe->name[0] = '\0'; /*XXX*/
procexe->name[0] = '\0';
if (pid == sigar_pid_get(sigar)) {
/*XXX*/
}
else {
status = sigar_pgrab(sigar, pid, SIGAR_FUNC, &phandle);
if (status == SIGAR_OK) {
sigar->pexename(phandle, procexe->name, sizeof(procexe->name));
sigar->pfree(phandle);
}
}
if (procexe->name[0] == '\0') {
/*XXX*/
}
(void)SIGAR_PROC_FILENAME(buffer, pid, "/cwd");
if (!sigar->pdirname(buffer, procexe->cwd, sizeof(procexe->cwd))) {