Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Commit

Permalink
Solaris: Implement process environment listing
Browse files Browse the repository at this point in the history
  • Loading branch information
Guy M. Broome authored and hishamhm committed Apr 5, 2018
1 parent 155d7cb commit 0969f83
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
44 changes: 42 additions & 2 deletions solaris/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,21 @@ in the source distribution for its full text.
#include "SignalsPanel.h"
#include <signal.h>
#include <sys/mkdev.h>
#include <sys/proc.h>
#include <libproc.h>
#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};
Expand Down Expand Up @@ -211,7 +220,38 @@ void Platform_setSwapValues(Meter* this) {
this->values[0] = pl->usedSwap;
}

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) {
(void) pid;
return "Not (yet) supported on Solaris. Sorry!";
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;
}
9 changes: 9 additions & 0 deletions solaris/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,21 @@ in the source distribution for its full text.
#include "SignalsPanel.h"
#include <signal.h>
#include <sys/mkdev.h>
#include <sys/proc.h>
#include <libproc.h>

#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];

Expand Down

0 comments on commit 0969f83

Please sign in to comment.