Commit 4e98d4fa authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(getloadavg): Add new code for SUNOS_5 to use -lkstat.

parent fe42a920
......@@ -391,6 +391,7 @@ extern int errno;
#ifdef SUNOS_5
#include <fcntl.h>
#include <kvm.h>
#include <kstat.h>
#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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment