From 4e98d4faa2002c6a574f7fab038ccea1ea9947e8 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Tue, 10 Sep 1996 19:50:17 +0000 Subject: [PATCH] (getloadavg): Add new code for SUNOS_5 to use -lkstat. --- src/getloadavg.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/getloadavg.c b/src/getloadavg.c index 1285408b875..2411e6a9225 100644 --- a/src/getloadavg.c +++ b/src/getloadavg.c @@ -391,6 +391,7 @@ extern int errno; #ifdef SUNOS_5 #include #include +#include #endif #ifndef KERNEL_FILE @@ -516,6 +517,50 @@ getloadavg (loadavg, nelem) elem = -1; #endif +#if !defined (LDAV_DONE) && defined (SUNOS_5) +/* Use libkstat because we don't have to be root. */ +#define LDAV_DONE + kstat_ctl_t *kc; + kstat_t *ksp; + kstat_named_t *kn; + + kc = kstat_open (); + if (kc == 0) return -1; + ksp = kstat_lookup (kc, "unix", 0, "system_misc"); + if (ksp == 0 ) return -1; + if (kstat_read (kc, ksp, 0) == -1) return -1; + + + kn = kstat_data_lookup (ksp, "avenrun_1min"); + if (kn == 0) + { + /* Return -1 if no load average information is available. */ + nelem = 0; + elem = -1; + } + + if (nelem >= 1) + loadavg[elem++] = (double) kn->value.ul/FSCALE; + + if (nelem >= 2) + { + kn = kstat_data_lookup (ksp, "avenrun_5min"); + if (kn != 0) + { + loadavg[elem++] = (double) kn->value.ul/FSCALE; + + if (nelem >= 3) + { + kn = kstat_data_lookup (ksp, "avenrun_15min"); + if (kn != 0) + loadavg[elem++] = (double) kn->value.ul/FSCALE; + } + } + } + + kstat_close (kc); +#endif /* SUNOS_5 */ + #if !defined (LDAV_DONE) && defined (__linux__) #define LDAV_DONE #undef LOAD_AVE_TYPE -- 2.39.2