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