* `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 $ */
/* *********************************************************** */
/* 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
/* 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
/* 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
#define _POSIX_SOURCE 1
+
/* Local headers */
#include "getloadavg.h"
/* Global functions */
+#ifdef HAVE_KSTAT
+
+#include <kstat.h>
+
+/* Copyright 2000-2001 Thomas Whateley <Thomas_Whateley@health.qld.gov.au> */
+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; cnt<ksp->ks_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,
fclose(fp);
return (i<0) ? i : i;
}
+
+#endif /* def HAVE_KSTAT */