1 # Check for getloadavg.
3 # Copyright (C) 1992-1996, 1999-2000, 2002-2003, 2006, 2008-2010 Free Software
6 # This file is free software; the Free Software Foundation
7 # gives unlimited permission to copy and/or distribute it,
8 # with or without modifications, as long as this notice is preserved.
12 # Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent.
13 # New applications should use gl_GETLOADAVG instead.
15 # gl_GETLOADAVG(LIBOBJDIR)
16 # ------------------------
17 AC_DEFUN([gl_GETLOADAVG],
18 [AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
20 # Persuade glibc <stdlib.h> to declare getloadavg().
21 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
23 gl_have_func=no # yes means we've found a way to get the load average.
25 # Make sure getloadavg.c is where it belongs, at configure-time.
26 test -f "$srcdir/$1/getloadavg.c" ||
27 AC_MSG_ERROR([$srcdir/$1/getloadavg.c is missing])
31 # Check for getloadavg, but be sure not to touch the cache variable.
32 (AC_CHECK_FUNC([getloadavg], [exit 0], [exit 1])) && gl_have_func=yes
34 # On HPUX9, an unprivileged user can get load averages through this function.
35 AC_CHECK_FUNCS([pstat_getdynamic])
37 # Solaris has libkstat which does not require root.
38 AC_CHECK_LIB([kstat], [kstat_open])
39 test $ac_cv_lib_kstat_kstat_open = yes && gl_have_func=yes
41 # AIX has libperfstat which does not require root
42 AC_CHECK_LIB([perfstat], [perfstat_cpu_total])
43 test $ac_cv_lib_perfstat_perfstat_cpu_total = yes && gl_have_func=yes
45 # Some systems with -lutil have (and need) -lkvm as well, some do not.
46 # On Solaris, -lkvm requires nlist from -lelf, so check that first
47 # to get the right answer into the cache.
48 # For kstat on solaris, we need libelf to force the definition of SVR4 below.
49 if test $gl_have_func = no; then
50 AC_CHECK_LIB([elf], [elf_begin], [LIBS="-lelf $LIBS"])
52 if test $gl_have_func = no; then
53 AC_CHECK_LIB([kvm], [kvm_open], [LIBS="-lkvm $LIBS"])
54 # Check for the 4.4BSD definition of getloadavg.
55 AC_CHECK_LIB([util], [getloadavg],
56 [LIBS="-lutil $LIBS" gl_have_func=yes gl_cv_func_getloadavg_setgid=yes])
59 if test $gl_have_func = no; then
60 # There is a commonly available library for RS/6000 AIX.
61 # Since it is not a standard part of AIX, it might be installed locally.
62 gl_getloadavg_LIBS=$LIBS
63 LIBS="-L/usr/local/lib $LIBS"
64 AC_CHECK_LIB([getloadavg], [getloadavg],
65 [LIBS="-lgetloadavg $LIBS"], [LIBS=$gl_getloadavg_LIBS])
68 # Make sure it is really in the library, if we think we found it,
69 # otherwise set up the replacement function.
70 AC_CHECK_FUNCS([getloadavg], [],
71 [gl_PREREQ_GETLOADAVG])
73 # Some definitions of getloadavg require that the program be installed setgid.
74 AC_CACHE_CHECK([whether getloadavg requires setgid],
75 gl_cv_func_getloadavg_setgid,
76 [AC_EGREP_CPP([Yowza Am I SETGID yet],
77 [#define CONFIGURING_GETLOADAVG
78 #include "$srcdir/$1/getloadavg.c"
79 #ifdef LDAV_PRIVILEGED
83 gl_cv_func_getloadavg_setgid=yes,
84 gl_cv_func_getloadavg_setgid=no)])
85 if test $gl_cv_func_getloadavg_setgid = yes; then
87 AC_DEFINE([GETLOADAVG_PRIVILEGED], [1],
88 [Define to 1 if the `getloadavg' function needs to be run setuid
93 AC_SUBST([NEED_SETGID])dnl
95 if test $gl_cv_func_getloadavg_setgid = yes; then
96 AC_CACHE_CHECK([group of /dev/kmem], [gl_cv_group_kmem],
97 [ # On Solaris, /dev/kmem is a symlink. Get info on the real file.
98 ac_ls_output=`ls -lgL /dev/kmem 2>/dev/null`
99 # If we got an error (system does not support symlinks), try without -L.
100 test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem`
101 gl_cv_group_kmem=`echo $ac_ls_output \
102 | sed -ne ['s/[ ][ ]*/ /g
103 s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\) *.*/\1/
106 AC_SUBST([KMEM_GROUP], [$gl_cv_group_kmem])dnl
108 if test "x$gl_save_LIBS" = x; then
109 GETLOADAVG_LIBS=$LIBS
111 GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$gl_save_LIBS!!"`
115 AC_SUBST([GETLOADAVG_LIBS])dnl
117 # Test whether the system declares getloadavg. Solaris has the function
118 # but declares it in <sys/loadavg.h>, not <stdlib.h>.
119 AC_CHECK_HEADERS([sys/loadavg.h])
120 if test $ac_cv_header_sys_loadavg_h = yes; then
125 AC_CHECK_DECL([getloadavg], [], [HAVE_DECL_GETLOADAVG=0],
126 [#if HAVE_SYS_LOADAVG_H
127 # include <sys/loadavg.h>
129 #include <stdlib.h>])
133 # gl_PREREQ_GETLOADAVG
134 # --------------------
135 # Set up the AC_LIBOBJ replacement of `getloadavg'.
136 AC_DEFUN([gl_PREREQ_GETLOADAVG],
137 [AC_LIBOBJ([getloadavg])
138 AC_DEFINE([C_GETLOADAVG], [1], [Define to 1 if using `getloadavg.c'.])
139 # Figure out what our getloadavg.c needs.
141 AC_CHECK_HEADER([sys/dg_sys_info.h],
143 AC_DEFINE([DGUX], [1], [Define to 1 for DGUX with <sys/dg_sys_info.h>.])
144 AC_CHECK_LIB([dgc], [dg_sys_info])])
146 # We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
147 # uses stabs), but it is still SVR4. We cannot check for <elf.h> because
148 # Irix 4.0.5F has the header but not the library.
149 if test $gl_have_func = no && test "$ac_cv_lib_elf_elf_begin" = yes \
150 && test "$ac_cv_lib_kvm_kvm_open" = yes; then
152 AC_DEFINE([SVR4], [1], [Define to 1 on System V Release 4.])
155 if test $gl_have_func = no; then
156 AC_CHECK_HEADER([inq_stats/cpustats.h],
158 AC_DEFINE([UMAX], [1], [Define to 1 for Encore UMAX.])
159 AC_DEFINE([UMAX4_3], [1],
160 [Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h>
161 instead of <sys/cpustats.h>.])])
164 if test $gl_have_func = no; then
165 AC_CHECK_HEADER([sys/cpustats.h],
166 [gl_have_func=yes; AC_DEFINE([UMAX])])
169 if test $gl_have_func = no; then
170 AC_CHECK_HEADERS([mach/mach.h])
173 AC_CHECK_HEADERS([nlist.h],
174 [AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
175 [AC_DEFINE([NLIST_NAME_UNION], [1],
176 [Define to 1 if your `struct nlist' has an
177 `n_un' member. Obsolete, depend on
178 `HAVE_STRUCT_NLIST_N_UN_N_NAME])], [],
179 [@%:@include <nlist.h>])
180 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <nlist.h>]],
182 #ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME
187 [AC_DEFINE([N_NAME_POINTER], [1],
188 [Define to 1 if the nlist n_name member is a pointer])])
190 ])# gl_PREREQ_GETLOADAVG