From: thib Date: Tue, 5 Jun 2001 10:18:16 +0000 (+0000) Subject: added support of kstat for getloadavg under Solaris X-Git-Tag: ver1564~247 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7dfb366431422ced02cffc459df4482e0984f35f;p=fcron added support of kstat for getloadavg under Solaris --- diff --git a/config.h.in b/config.h.in index 9e45de4..2977d6f 100644 --- a/config.h.in +++ b/config.h.in @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: config.h.in,v 1.30 2001-06-03 10:59:09 thib Exp $ */ + /* $Id: config.h.in,v 1.31 2001-06-05 10:18:16 thib Exp $ */ /* *********************************************************** */ @@ -195,18 +195,18 @@ /* Define on System V Release 4. */ #undef SVR4 +/* Define if you have the flock function. */ +#undef HAVE_FLOCK + +/* Define if you have the lockf function. */ +#undef HAVE_LOCKF + /* Define if your system has its own `getloadavg' function. */ #undef HAVE_GETLOADAVG /* Define if the `getloadavg' function needs to be run setuid or setgid. */ #undef GETLOADAVG_PRIVILEGED -/* Define if you have the strftime function. */ -#undef HAVE_STRFTIME - -/* Define if you have the wait3 system call. */ -#undef HAVE_WAIT3 - /* Define if you have the getcwd function. */ #undef HAVE_GETCWD @@ -216,11 +216,8 @@ /* Define if you have the gettimeofday function. */ #undef HAVE_GETTIMEOFDAY -/* Define if you have the flock function. */ -#undef HAVE_FLOCK - -/* Define if you have the lockf function. */ -#undef HAVE_LOCKF +/* Define if you have the kstat* functions. */ +#undef HAVE_KSTAT /* Define if you have the mkstemp function. */ #undef HAVE_MKSTEMP @@ -243,6 +240,12 @@ /* Define if you have the strerror function. */ #undef HAVE_STRERROR +/* Define if you have the strftime function. */ +#undef HAVE_STRFTIME + +/* Define if you have the wait3 system call. */ +#undef HAVE_WAIT3 + /* Define if you have the ANSI C header files. */ #undef STDC_HEADERS diff --git a/getloadavg.c b/getloadavg.c index 7af3334..7f056c8 100644 --- a/getloadavg.c +++ b/getloadavg.c @@ -22,12 +22,65 @@ #define _POSIX_SOURCE 1 + /* Local headers */ #include "getloadavg.h" /* Global functions */ +#ifdef HAVE_KSTAT + +#include + +/* Copyright 2000-2001 Thomas Whateley */ +int +getloadavg(double *result, int n) +/* return the current load average as a floating point number, + * the number of load averages read, or <0 for error + */ +{ + kstat_ctl_t *kc; + kstat_t *ksp; + kstat_named_t *knm; + kstat_named_t knm_buf[20]; + int cnt; + int ret; + + if ( n != 3) { + return -1; + } + + ret = 0; + + kc = kstat_open(); + for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) { + if (strcmp(ksp->ks_name, "system_misc") == 0) { + kstat_read(kc, ksp, &knm_buf); + for (cnt=0; cntks_ndata; cnt++) { + knm=&knm_buf[cnt]; + if (strcmp(knm->name,"avenrun_1min") == 0) { + result[0] = knm->value.ui32 / 256.0; + ret++; + } + else if (strcmp(knm->name,"avenrun_5min") == 0) { + result[1] = knm->value.ui32 / 256.0; + ret++; + } + else if (strcmp(knm->name,"avenrun_15min") == 0) { + result[2] = knm->value.ui32 / 256.0; + ret++; + } + } + } + } + kstat_close(kc); + + return ret; +} + +#else /* def HAVE_KSTAT */ + int getloadavg(double *result, int n) /* return the current load average as a floating point number, @@ -56,3 +109,5 @@ getloadavg(double *result, int n) fclose(fp); return (i<0) ? i : i; } + +#endif /* def HAVE_KSTAT */