diff options
author | Michael Klein <michael.klein@puffin.lb.shuttle.de> | 2015-12-03 22:16:10 +0100 |
---|---|---|
committer | Michael Klein <michael.klein@puffin.lb.shuttle.de> | 2015-12-03 22:23:40 +0100 |
commit | cc23d13f87e74d4dc2cc781da28ddc07f3860b63 (patch) | |
tree | efba2e92a9fc328def3025ce52c707d4d5260b15 /EnvScreen.c | |
parent | 0919ea32f91bb2ddf349c1108f6f0f67b511cca6 (diff) |
Add Platform_getProcessEnv
- currently implemented for darwin and linux
Diffstat (limited to 'EnvScreen.c')
-rw-r--r-- | EnvScreen.c | 58 |
1 files changed, 11 insertions, 47 deletions
diff --git a/EnvScreen.c b/EnvScreen.c index 1076ed0a..c989d26f 100644 --- a/EnvScreen.c +++ b/EnvScreen.c @@ -1,14 +1,14 @@ #include "EnvScreen.h" +#include "config.h" #include "CRT.h" #include "IncSet.h" #include "ListItem.h" +#include "Platform.h" #include "StringUtils.h" #include <stdlib.h> #include <string.h> -#include <sys/sysctl.h> -#include <sys/types.h> #include <unistd.h> /*{ @@ -65,51 +65,15 @@ static void EnvScreen_scan(EnvScreen* this, Vector* lines, IncSet* inc) { Panel_prune(panel); if (uid == 0 || uid == this->process->st_uid) { - long argmax = sysconf(_SC_ARG_MAX); - char* buf = malloc(argmax); - size_t bufsz = argmax; - if (buf) { - int mib[3]; - mib[0] = CTL_KERN; - mib[1] = KERN_PROCARGS2; - mib[2] = this->process->pid; - bufsz = argmax; - if (sysctl(mib, 3, buf, &bufsz, 0, 0) == 0) { - if (bufsz > sizeof(int)) { - char *p = buf, *endp = buf + bufsz; - int argc = *(int*)p; - p += sizeof(int); - - // skip exe - p = strchr(p, 0)+1; - - // skip padding - while(!*p && p < endp) - ++p; - - // skip argv - for (; argc-- && p < endp; p = strrchr(p, 0)+1) - ; - - // skip padding - while(!*p && p < endp) - ++p; - - for (; *p && p < endp; p = strrchr(p, 0)+1) - addLine(p, lines, panel, IncSet_filter(inc)); - } - else { - addLine("Could not allocate memory.", lines, panel, IncSet_filter(inc)); - } - } - else { - addLine("sysctl(KERN_PROCARGS2) failed.", lines, panel, IncSet_filter(inc)); - } - free(buf); - } - else { - addLine("Out of memory.", lines, panel, IncSet_filter(inc)); - } + char *env = Platform_getProcessEnv(this->process->pid); + if (env) { + for (char *p = env; *p; p = strrchr(p, 0)+1) + addLine(p, lines, panel, IncSet_filter(inc)); + free(env); + } + else { + addLine("Could not read process environment.", lines, panel, IncSet_filter(inc)); + } } else { addLine("Process belongs to different user.", lines, panel, IncSet_filter(inc)); |