diff options
author | Daniel Lange <DLange@git.local> | 2020-11-15 14:32:41 +0100 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2020-11-15 14:33:09 +0100 |
commit | bb908f3dc4ac5847592e9698dec150658067e84e (patch) | |
tree | fb0d7b03602de14f4ba6efbdd9f8a9f3cf7cc067 /solaris/Platform.c | |
parent | da2dcf9505299eae607e29cc85691b8163c1a36e (diff) | |
parent | e7b95feee4f375738cb339a58337fdab83f6abbf (diff) |
Resolve merge conflicts, merge #298 "Macro cleanup" from @BenBE
Diffstat (limited to 'solaris/Platform.c')
-rw-r--r-- | solaris/Platform.c | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/solaris/Platform.c b/solaris/Platform.c index 8e08c025..1a505f84 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -130,7 +130,7 @@ extern char Process_pidFormat[20]; int Platform_getUptime() { int boot_time = 0; int curr_time = time(NULL); - struct utmpx * ent; + struct utmpx* ent; while (( ent = getutxent() )) { if ( !strcmp("system boot", ent->ut_line )) { @@ -140,7 +140,7 @@ int Platform_getUptime() { endutxent(); - return (curr_time-boot_time); + return (curr_time - boot_time); } void Platform_getLoadAverage(double* one, double* five, double* fifteen) { @@ -151,18 +151,24 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { } int Platform_getMaxPid() { - kstat_ctl_t *kc = NULL; - kstat_t *kshandle = NULL; - kvar_t *ksvar = NULL; + kstat_ctl_t* kc = NULL; + kstat_t* kshandle = NULL; + kvar_t* ksvar = NULL; int vproc = 32778; // Reasonable Solaris default kc = kstat_open(); - if (kc != NULL) { kshandle = kstat_lookup(kc,"unix",0,"var"); } - if (kshandle != NULL) { kstat_read(kc,kshandle,NULL); } + if (kc != NULL) { + kshandle = kstat_lookup(kc, "unix", 0, "var"); + } + if (kshandle != NULL) { + kstat_read(kc, kshandle, NULL); + } ksvar = kshandle->ks_data; if (ksvar->v_proc > 0 ) { vproc = ksvar->v_proc; } - if (kc != NULL) { kstat_close(kc); } + if (kc != NULL) { + kstat_close(kc); + } return vproc; } @@ -172,10 +178,10 @@ double Platform_setCPUValues(Meter* this, int cpu) { const CPUData* cpuData = NULL; if (cpus == 1) { - // single CPU box has everything in spl->cpus[0] - cpuData = &(spl->cpus[0]); + // single CPU box has everything in spl->cpus[0] + cpuData = &(spl->cpus[0]); } else { - cpuData = &(spl->cpus[cpu]); + cpuData = &(spl->cpus[cpu]); } double percent; @@ -187,15 +193,14 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[CPU_METER_KERNEL] = cpuData->systemPercent; v[CPU_METER_IRQ] = cpuData->irqPercent; this->curItems = 4; - percent = v[0]+v[1]+v[2]+v[3]; + percent = v[0] + v[1] + v[2] + v[3]; } else { v[2] = cpuData->systemAllPercent; this->curItems = 3; - percent = v[0]+v[1]+v[2]; + percent = v[0] + v[1] + v[2]; } - percent = CLAMP(percent, 0.0, 100.0); - if (isnan(percent)) percent = 0.0; + percent = isnan(percent) ? 0.0 : CLAMP(percent, 0.0, 100.0); v[CPU_METER_FREQUENCY] = NAN; @@ -228,15 +233,17 @@ void Platform_setZfsCompressedArcValues(Meter* this) { ZfsCompressedArcMeter_readStats(this, &(spl->zfs)); } -static int Platform_buildenv(void *accum, struct ps_prochandle *Phandle, uintptr_t addr, const char *str) { - envAccum *accump = accum; +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)) + if ((thissz + 2) > (accump->capacity - accump->size)) { accump->env = xRealloc(accump->env, accump->capacity *= 2); - if ((thissz + 2) > (accump->capacity - accump->size)) + } + 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; @@ -247,16 +254,17 @@ char* Platform_getProcessEnv(pid_t pid) { envAccum envBuilder; pid_t realpid = pid / 1024; int graberr; - struct ps_prochandle *Phandle; + struct ps_prochandle* Phandle; - if ((Phandle = Pgrab(realpid,PGRAB_RDONLY,&graberr)) == NULL) + 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); + (void) Penv_iter(Phandle, Platform_buildenv, &envBuilder); Prelease(Phandle, 0); @@ -281,10 +289,10 @@ bool Platform_getDiskIO(DiskIOData* data) { return false; } -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted) { +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted) { // TODO *bytesReceived = 0; *packetsReceived = 0; |