Solaris: reduce variable scope

Also check for getloadavg(3c) failure
This commit is contained in:
Christian Göttsche 2021-05-19 19:06:34 +02:00 committed by cgzones
parent 906dcf5cb3
commit 6b57898034
2 changed files with 7 additions and 5 deletions

View File

@ -39,8 +39,6 @@ in the source distribution for its full text.
#include "SolarisProcessList.h" #include "SolarisProcessList.h"
double plat_loadavg[3] = {0};
const SignalItem Platform_signals[] = { const SignalItem Platform_signals[] = {
{ .name = " 0 Cancel", .number = 0 }, { .name = " 0 Cancel", .number = 0 },
{ .name = " 1 SIGHUP", .number = 1 }, { .name = " 1 SIGHUP", .number = 1 },
@ -152,7 +150,13 @@ int Platform_getUptime() {
} }
void Platform_getLoadAverage(double* one, double* five, double* fifteen) { void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
getloadavg( plat_loadavg, 3 ); double plat_loadavg[3];
if (getloadavg( plat_loadavg, 3 ) < 0) {
*one = NAN;
*five = NAN;
*fifteen = NAN;
return;
}
*one = plat_loadavg[LOADAVG_1MIN]; *one = plat_loadavg[LOADAVG_1MIN];
*five = plat_loadavg[LOADAVG_5MIN]; *five = plat_loadavg[LOADAVG_5MIN];
*fifteen = plat_loadavg[LOADAVG_15MIN]; *fifteen = plat_loadavg[LOADAVG_15MIN];

View File

@ -42,8 +42,6 @@ typedef struct envAccum_ {
char* env; char* env;
} envAccum; } envAccum;
extern double plat_loadavg[3];
extern const SignalItem Platform_signals[]; extern const SignalItem Platform_signals[];
extern const unsigned int Platform_numberOfSignals; extern const unsigned int Platform_numberOfSignals;