diff options
author | Ross Williams <ross@ross-williams.net> | 2020-10-23 20:31:20 +0000 |
---|---|---|
committer | cgzones <cgzones@googlemail.com> | 2020-10-26 19:01:11 +0100 |
commit | 0ae2bb1f8e80f34571203df7fe31ba22ce9b8670 (patch) | |
tree | 252fce22ebc7401c0dd2bec794d53f0838310ee3 /freebsd | |
parent | 11bf7be9c2e1d83c0e4ae2ac9f0e3ccdc09ddbf1 (diff) |
Add process environment for FreeBSD
Diffstat (limited to 'freebsd')
-rw-r--r-- | freebsd/Platform.c | 28 |
1 files changed, 25 insertions, 3 deletions
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 <sys/resource.h> #include <vm/vm_param.h> #include <time.h> +#include <limits.h> #include <math.h> @@ -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) { |