getloadavg.m4 6.5 KB

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