diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-02-24 13:05:45 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-02-24 17:44:53 -0800 |
commit | d436ab2166c03a54e58f6f4b48e876ba1c147d13 (patch) | |
tree | d75550aef7a7dd1b63c8d1fa79238de51a4e1a84 /get_load.c | |
parent | b0613198f87af22be989fa54e785c64e147debb6 (diff) |
Make getloadavg() the first choice on Unix systems that have it
Only fall back to complex, platform specific code if the simpler,
more portable option isn't found by configure.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'get_load.c')
-rw-r--r-- | get_load.c | 54 |
1 files changed, 26 insertions, 28 deletions
@@ -101,8 +101,32 @@ void GetLoadPoint( if (ret!=0) return; *loadavg = (fmtvalue.u.vDouble-0.01)/100.0; } -#else +#else /* not CYGWIN */ + +static void xload_error(const char *, const char *) _X_NORETURN; +#ifdef HAVE_GETLOADAVG +#include <stdlib.h> +#ifdef HAVE_SYS_LOADAVG_H +#include <sys/loadavg.h> /* Solaris definition of getloadavg */ +#endif + +void InitLoadPoint(void) +{ +} + +void GetLoadPoint( + Widget w, /* unused */ + XtPointer closure, /* unused */ + XtPointer call_data) /* ptr to (double) return value */ +{ + double *loadavg = (double *)call_data; + + if (getloadavg(loadavg, 1) < 0) + xload_error("couldn't obtain load average", ""); +} + +#else /* not HAVE_GETLOADAVG */ #if defined(att) || defined(QNX4) #define LOADSTUB @@ -140,9 +164,6 @@ void GetLoadPoint( #endif #endif -static void xload_error(const char *, const char *) _X_NORETURN; - - #if defined(SYSV) && defined(i386) /* * inspired by 'avgload' by John F. Haugh II @@ -490,29 +511,6 @@ void GetLoadPoint( } #else /* not __bsdi__ */ -#if defined(HAVE_GETLOADAVG) -#include <stdlib.h> -#ifdef HAVE_SYS_LOADAVG_H -#include <sys/loadavg.h> /* Solaris definition of getloadavg */ -#endif - -void InitLoadPoint() -{ -} - -void GetLoadPoint(w, closure, call_data) - Widget w; /* unused */ - XtPointer closure; /* unused */ - XtPointer call_data; /* ptr to (double) return value */ -{ - double *loadavg = (double *)call_data; - - if (getloadavg(loadavg, 1) < 0) - xload_error("couldn't obtain load average", ""); -} - -#else /* not HAVE_GETLOADAVG */ - #ifndef KMEM_FILE #define KMEM_FILE "/dev/kmem" #endif @@ -647,7 +645,6 @@ void GetLoadPoint( w, closure, call_data ) #endif /* SVR4 or ... else */ return; } -#endif /* HAVE_GETLOADAVG else */ #endif /* __bsdi__ else */ #endif /* __QNXNTO__ else */ #endif /* __osf__ else */ @@ -656,6 +653,7 @@ void GetLoadPoint( w, closure, call_data ) #endif /* __GNU__ else */ #endif /* linux else */ #endif /* SYSV && i386 else */ +#endif /* HAVE_GETLOADAVG else */ static void xload_error(const char *str1, const char *str2) { |