From d8159a60240d7ec5900a0e5be0e565a2ec6a8f63 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 29 Aug 2006 01:43:48 +0000 Subject: [PATCH] attempt to determine cwd from $PWD --- src/os/darwin/darwin_sigar.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index 0cd8ce13..5cbc0c28 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -1262,6 +1262,30 @@ int sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid, procexe->cwd[0] = '\0'; procexe->root[0] = '\0'; + /* attempt to determine cwd from $PWD */ + status = kern_proc_args_skip_argv(&kargs); + if (status == SIGAR_OK) { + char *ptr = kargs.ptr; + char *end = kargs.end; + + /* into environ */ + while (ptr < end) { + int len = strlen(ptr); + + if ((len > 4) && + (ptr[0] == 'P') && + (ptr[1] == 'W') && + (ptr[2] == 'D') && + (ptr[3] == '=')) + { + memcpy(procexe->cwd, ptr+4, len-3); + break; + } + + ptr += len+1; + } + } + return SIGAR_OK; #else int len;