From 0ae2bb1f8e80f34571203df7fe31ba22ce9b8670 Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Fri, 23 Oct 2020 20:31:20 +0000 Subject: Add process environment for FreeBSD --- freebsd/Platform.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'freebsd') diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 2f7f2640..0515558f 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -32,6 +32,7 @@ in the source distribution for its full text. #include #include #include +#include #include @@ -220,9 +221,30 @@ void Platform_setZfsCompressedArcValues(Meter* this) { } char* Platform_getProcessEnv(pid_t pid) { - (void) pid; - // TODO - return NULL; + int mib[4]; + char *env = NULL; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_ENV; + mib[3] = pid; + + size_t capacity = ARG_MAX; + env = xMalloc(capacity); + + int err = sysctl(mib, 4, env, &capacity, NULL, 0); + if (err) { + free(env); + return NULL; + } + + if (env[capacity-1] || env[capacity-2]) { + env = xRealloc(env, capacity+2); + env[capacity] = 0; + env[capacity+1] = 0; + } + + return env; } void Platform_getDiskIO(unsigned long int *bytesRead, unsigned long int *bytesWrite, unsigned long int *msTimeSpend) { -- cgit v1.2.3