From beb47cbb121607a4ef4601923ad09a58cac1d723 Mon Sep 17 00:00:00 2001 From: "Guy M. Broome" Date: Thu, 29 Mar 2018 13:28:43 -0400 Subject: [PATCH] Solaris: Implement process environment listing --- solaris/Platform.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- solaris/Platform.h | 9 +++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/solaris/Platform.c b/solaris/Platform.c index ebcd2a28..c6e9c1b8 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -37,12 +37,21 @@ in the source distribution for its full text. #include "SignalsPanel.h" #include #include +#include +#include #define kill(pid, signal) kill(pid / 1024, signal) extern ProcessFieldData Process_fields[]; typedef struct var kvar_t; +typedef struct envAccum_ { + size_t capacity; + size_t size; + size_t bytes; + char *env; +} envAccum; + }*/ double plat_loadavg[3] = {0}; @@ -211,7 +220,38 @@ void Platform_setSwapValues(Meter* this) { this->values[0] = pl->usedSwap; } -char* Platform_getProcessEnv(pid_t pid) { - (void) pid; - return "Not (yet) supported on Solaris. Sorry!"; +static int Platform_buildenv(void *accum, struct ps_prochandle *Phandle, uintptr_t addr, const char *str) { + envAccum *accump = accum; + (void) Phandle; + (void) addr; + size_t thissz = strlen(str); + if ((thissz + 2) > (accump->capacity - accump->size)) + accump->env = xRealloc(accump->env, accump->capacity *= 2); + if ((thissz + 2) > (accump->capacity - accump->size)) + return 1; + strlcpy( accump->env + accump->size, str, (accump->capacity - accump->size)); + strncpy( accump->env + accump->size + thissz + 1, "\n", 1); + accump->size = accump->size + thissz + 1; + return 0; +} + +char* Platform_getProcessEnv(pid_t pid) { + envAccum envBuilder; + pid_t realpid = pid / 1024; + int graberr; + struct ps_prochandle *Phandle; + + if ((Phandle = Pgrab(realpid,PGRAB_RDONLY,&graberr)) == NULL) + return "Unable to read process environment."; + + envBuilder.capacity = 4096; + envBuilder.size = 0; + envBuilder.env = xMalloc(envBuilder.capacity); + + (void) Penv_iter(Phandle,Platform_buildenv,&envBuilder); + + Prelease(Phandle, 0); + + strncpy( envBuilder.env + envBuilder.size, "\0", 1); + return envBuilder.env; } diff --git a/solaris/Platform.h b/solaris/Platform.h index 01ffa59b..6b820fea 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -16,12 +16,21 @@ in the source distribution for its full text. #include "SignalsPanel.h" #include #include +#include +#include #define kill(pid, signal) kill(pid / 1024, signal) extern ProcessFieldData Process_fields[]; typedef struct var kvar_t; +typedef struct envAccum_ { + size_t capacity; + size_t size; + size_t bytes; + char *env; +} envAccum; + extern double plat_loadavg[3];