From cc23d13f87e74d4dc2cc781da28ddc07f3860b63 Mon Sep 17 00:00:00 2001 From: Michael Klein Date: Thu, 3 Dec 2015 22:16:10 +0100 Subject: Add Platform_getProcessEnv - currently implemented for darwin and linux --- EnvScreen.c | 58 +++++++++++----------------------------------------------- 1 file changed, 11 insertions(+), 47 deletions(-) (limited to 'EnvScreen.c') 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 #include -#include -#include #include /*{ @@ -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)); -- cgit v1.2.3