getloadavg.m4 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #serial 9
  2. # A replacement for autoconf's macro by the same name. This version
  3. # accepts an optional argument specifying the name of the $srcdir-relative
  4. # directory in which the file getloadavg.c may be found. It is unusual
  5. # (but justified, imho) that this file is required at ./configure time.
  6. undefine([AC_FUNC_GETLOADAVG])
  7. # AC_FUNC_GETLOADAVG
  8. # ------------------
  9. AC_DEFUN([AC_FUNC_GETLOADAVG],
  10. [ac_have_func=no # yes means we've found a way to get the load average.
  11. AC_CHECK_HEADERS(locale.h unistd.h mach/mach.h fcntl.h)
  12. AC_CHECK_FUNCS(setlocale)
  13. # By default, expect to find getloadavg.c in $srcdir/.
  14. ac_lib_dir_getloadavg=$srcdir
  15. # But if there's an argument, DIR, expect to find getloadavg.c in $srcdir/DIR.
  16. m4_ifval([$1], [ac_lib_dir_getloadavg=$srcdir/$1])
  17. # Make sure getloadavg.c is where it belongs, at ./configure-time.
  18. test -f $ac_lib_dir_getloadavg/getloadavg.c \
  19. || AC_MSG_ERROR([getloadavg.c is not in $ac_lib_dir_getloadavg])
  20. # FIXME: Add an autoconf-time test, too?
  21. ac_save_LIBS=$LIBS
  22. # Check for getloadavg, but be sure not to touch the cache variable.
  23. (AC_CHECK_FUNC(getloadavg, exit 0, exit 1)) && ac_have_func=yes
  24. # On HPUX9, an unprivileged user can get load averages through this function.
  25. AC_CHECK_FUNCS(pstat_getdynamic)
  26. # Solaris has libkstat which does not require root.
  27. AC_CHECK_LIB(kstat, kstat_open)
  28. test $ac_cv_lib_kstat_kstat_open = yes && ac_have_func=yes
  29. # Some systems with -lutil have (and need) -lkvm as well, some do not.
  30. # On Solaris, -lkvm requires nlist from -lelf, so check that first
  31. # to get the right answer into the cache.
  32. # For kstat on solaris, we need libelf to force the definition of SVR4 below.
  33. if test $ac_have_func = no; then
  34. AC_CHECK_LIB(elf, elf_begin, LIBS="-lelf $LIBS")
  35. fi
  36. if test $ac_have_func = no; then
  37. AC_CHECK_LIB(kvm, kvm_open, LIBS="-lkvm $LIBS")
  38. # Check for the 4.4BSD definition of getloadavg.
  39. AC_CHECK_LIB(util, getloadavg,
  40. [LIBS="-lutil $LIBS" ac_have_func=yes ac_cv_func_getloadavg_setgid=yes])
  41. fi
  42. if test $ac_have_func = no; then
  43. # There is a commonly available library for RS/6000 AIX.
  44. # Since it is not a standard part of AIX, it might be installed locally.
  45. ac_getloadavg_LIBS=$LIBS
  46. LIBS="-L/usr/local/lib $LIBS"
  47. AC_CHECK_LIB(getloadavg, getloadavg,
  48. [LIBS="-lgetloadavg $LIBS"], [LIBS=$ac_getloadavg_LIBS])
  49. fi
  50. # Make sure it is really in the library, if we think we found it,
  51. # otherwise set up the replacement function.
  52. AC_CHECK_FUNCS(getloadavg, [],
  53. [_AC_LIBOBJ_GETLOADAVG])
  54. # Some definitions of getloadavg require that the program be installed setgid.
  55. AC_CACHE_CHECK(whether getloadavg requires setgid,
  56. ac_cv_func_getloadavg_setgid,
  57. [AC_EGREP_CPP([Yowza Am I SETGID yet],
  58. [#include "$ac_lib_dir_getloadavg/getloadavg.c"
  59. #ifdef LDAV_PRIVILEGED
  60. Yowza Am I SETGID yet
  61. @%:@endif],
  62. ac_cv_func_getloadavg_setgid=yes,
  63. ac_cv_func_getloadavg_setgid=no)])
  64. if test $ac_cv_func_getloadavg_setgid = yes; then
  65. NEED_SETGID=true
  66. AC_DEFINE(GETLOADAVG_PRIVILEGED, 1,
  67. [Define if the `getloadavg' function needs to be run setuid
  68. or setgid.])
  69. else
  70. NEED_SETGID=false
  71. fi
  72. AC_SUBST(NEED_SETGID)dnl
  73. if test $ac_cv_func_getloadavg_setgid = yes; then
  74. AC_CACHE_CHECK(group of /dev/kmem, ac_cv_group_kmem,
  75. [ # On Solaris, /dev/kmem is a symlink. Get info on the real file.
  76. ac_ls_output=`ls -lgL /dev/kmem 2>/dev/null`
  77. # If we got an error (system does not support symlinks), try without -L.
  78. test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem`
  79. ac_cv_group_kmem=`echo $ac_ls_output \
  80. | sed -ne ['s/[ ][ ]*/ /g;
  81. s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\) *.*/\1/;
  82. / /s/.* //;p;']`
  83. ])
  84. AC_SUBST(KMEM_GROUP, $ac_cv_group_kmem)dnl
  85. fi
  86. if test "x$ac_save_LIBS" = x; then
  87. GETLOADAVG_LIBS=$LIBS
  88. else
  89. GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$ac_save_LIBS!!"`
  90. fi
  91. LIBS=$ac_save_LIBS
  92. AC_SUBST(GETLOADAVG_LIBS)dnl
  93. ])# AC_FUNC_GETLOADAVG