summaryrefslogtreecommitdiffstats
path: root/gl/m4/getloadavg.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/getloadavg.m4')
-rw-r--r--gl/m4/getloadavg.m4155
1 files changed, 155 insertions, 0 deletions
diff --git a/gl/m4/getloadavg.m4 b/gl/m4/getloadavg.m4
new file mode 100644
index 0000000..8243729
--- /dev/null
+++ b/gl/m4/getloadavg.m4
@@ -0,0 +1,155 @@
1# Check for getloadavg.
2
3# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2002, 2003,
4# 2006 Free Software Foundation, Inc.
5
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.
9
10# Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent.
11# New applications should use gl_GETLOADAVG instead.
12
13# gl_GETLOADAVG(LIBOBJDIR)
14# ------------------------
15AC_DEFUN([gl_GETLOADAVG],
16[gl_have_func=no # yes means we've found a way to get the load average.
17
18# Make sure getloadavg.c is where it belongs, at configure-time.
19test -f "$srcdir/$1/getloadavg.c" ||
20 AC_MSG_ERROR([$srcdir/$1/getloadavg.c is missing])
21
22gl_save_LIBS=$LIBS
23
24# Check for getloadavg, but be sure not to touch the cache variable.
25(AC_CHECK_FUNC(getloadavg, exit 0, exit 1)) && gl_have_func=yes
26
27# On HPUX9, an unprivileged user can get load averages through this function.
28AC_CHECK_FUNCS(pstat_getdynamic)
29
30# Solaris has libkstat which does not require root.
31AC_CHECK_LIB(kstat, kstat_open)
32test $ac_cv_lib_kstat_kstat_open = yes && gl_have_func=yes
33
34# Some systems with -lutil have (and need) -lkvm as well, some do not.
35# On Solaris, -lkvm requires nlist from -lelf, so check that first
36# to get the right answer into the cache.
37# For kstat on solaris, we need libelf to force the definition of SVR4 below.
38if test $gl_have_func = no; then
39 AC_CHECK_LIB(elf, elf_begin, LIBS="-lelf $LIBS")
40fi
41if test $gl_have_func = no; then
42 AC_CHECK_LIB(kvm, kvm_open, LIBS="-lkvm $LIBS")
43 # Check for the 4.4BSD definition of getloadavg.
44 AC_CHECK_LIB(util, getloadavg,
45 [LIBS="-lutil $LIBS" gl_have_func=yes gl_cv_func_getloadavg_setgid=yes])
46fi
47
48if test $gl_have_func = no; then
49 # There is a commonly available library for RS/6000 AIX.
50 # Since it is not a standard part of AIX, it might be installed locally.
51 gl_getloadavg_LIBS=$LIBS
52 LIBS="-L/usr/local/lib $LIBS"
53 AC_CHECK_LIB(getloadavg, getloadavg,
54 [LIBS="-lgetloadavg $LIBS"], [LIBS=$gl_getloadavg_LIBS])
55fi
56
57# Make sure it is really in the library, if we think we found it,
58# otherwise set up the replacement function.
59AC_CHECK_FUNCS(getloadavg, [],
60 [gl_PREREQ_GETLOADAVG])
61
62# Some definitions of getloadavg require that the program be installed setgid.
63AC_CACHE_CHECK(whether getloadavg requires setgid,
64 gl_cv_func_getloadavg_setgid,
65[AC_EGREP_CPP([Yowza Am I SETGID yet],
66[#define CONFIGURING_GETLOADAVG
67#include "$srcdir/$1/getloadavg.c"
68#ifdef LDAV_PRIVILEGED
69Yowza Am I SETGID yet
70#endif
71],
72 gl_cv_func_getloadavg_setgid=yes,
73 gl_cv_func_getloadavg_setgid=no)])
74if test $gl_cv_func_getloadavg_setgid = yes; then
75 NEED_SETGID=true
76 AC_DEFINE(GETLOADAVG_PRIVILEGED, 1,
77 [Define to 1 if the `getloadavg' function needs to be run setuid
78 or setgid.])
79else
80 NEED_SETGID=false
81fi
82AC_SUBST(NEED_SETGID)dnl
83
84if test $gl_cv_func_getloadavg_setgid = yes; then
85 AC_CACHE_CHECK(group of /dev/kmem, gl_cv_group_kmem,
86[ # On Solaris, /dev/kmem is a symlink. Get info on the real file.
87 ac_ls_output=`ls -lgL /dev/kmem 2>/dev/null`
88 # If we got an error (system does not support symlinks), try without -L.
89 test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem`
90 gl_cv_group_kmem=`echo $ac_ls_output \
91 | sed -ne ['s/[ ][ ]*/ /g
92 s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\) *.*/\1/
93 / /s/.* //;p']`
94])
95 AC_SUBST(KMEM_GROUP, $gl_cv_group_kmem)dnl
96fi
97if test "x$gl_save_LIBS" = x; then
98 GETLOADAVG_LIBS=$LIBS
99else
100 GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$gl_save_LIBS!!"`
101fi
102LIBS=$gl_save_LIBS
103
104AC_SUBST(GETLOADAVG_LIBS)dnl
105])# gl_GETLOADAVG
106
107
108# gl_PREREQ_GETLOADAVG
109# --------------------
110# Set up the AC_LIBOBJ replacement of `getloadavg'.
111AC_DEFUN([gl_PREREQ_GETLOADAVG],
112[AC_LIBOBJ(getloadavg)
113AC_DEFINE(C_GETLOADAVG, 1, [Define to 1 if using `getloadavg.c'.])
114# Figure out what our getloadavg.c needs.
115gl_have_func=no
116AC_CHECK_HEADER(sys/dg_sys_info.h,
117[gl_have_func=yes
118 AC_DEFINE(DGUX, 1, [Define to 1 for DGUX with <sys/dg_sys_info.h>.])
119 AC_CHECK_LIB(dgc, dg_sys_info)])
120
121# We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
122# uses stabs), but it is still SVR4. We cannot check for <elf.h> because
123# Irix 4.0.5F has the header but not the library.
124if test $gl_have_func = no && test "$ac_cv_lib_elf_elf_begin" = yes; then
125 gl_have_func=yes
126 AC_DEFINE(SVR4, 1, [Define to 1 on System V Release 4.])
127fi
128
129if test $gl_have_func = no; then
130 AC_CHECK_HEADER(inq_stats/cpustats.h,
131 [gl_have_func=yes
132 AC_DEFINE(UMAX, 1, [Define to 1 for Encore UMAX.])
133 AC_DEFINE(UMAX4_3, 1,
134 [Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h>
135 instead of <sys/cpustats.h>.])])
136fi
137
138if test $gl_have_func = no; then
139 AC_CHECK_HEADER(sys/cpustats.h,
140 [gl_have_func=yes; AC_DEFINE(UMAX)])
141fi
142
143if test $gl_have_func = no; then
144 AC_CHECK_HEADERS(mach/mach.h)
145fi
146
147AC_CHECK_HEADERS(nlist.h,
148[AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
149 [AC_DEFINE(NLIST_NAME_UNION, 1,
150 [Define to 1 if your `struct nlist' has an
151 `n_un' member. Obsolete, depend on
152 `HAVE_STRUCT_NLIST_N_UN_N_NAME])], [],
153 [@%:@include <nlist.h>])
154])dnl
155])# gl_PREREQ_GETLOADAVG