getloadavg.m4 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # Check for getloadavg.
  2. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2002, 2003,
  3. # 2006 Free Software 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. [gl_have_func=no # yes means we've found a way to get the load average.
  13. # Make sure getloadavg.c is where it belongs, at configure-time.
  14. test -f "$srcdir/$1/getloadavg.c" ||
  15. AC_MSG_ERROR([$srcdir/$1/getloadavg.c is missing])
  16. gl_save_LIBS=$LIBS
  17. # Check for getloadavg, but be sure not to touch the cache variable.
  18. (AC_CHECK_FUNC(getloadavg, exit 0, exit 1)) && gl_have_func=yes
  19. # On HPUX9, an unprivileged user can get load averages through this function.
  20. AC_CHECK_FUNCS(pstat_getdynamic)
  21. # Solaris has libkstat which does not require root.
  22. AC_CHECK_LIB(kstat, kstat_open)
  23. test $ac_cv_lib_kstat_kstat_open = yes && gl_have_func=yes
  24. # AIX has libperfstat which does not require root
  25. AC_CHECK_LIB(perfstat, perfstat_cpu_total)
  26. test $ac_cv_lib_perfstat_perfstat_cpu_total = yes && gl_have_func=yes
  27. # Some systems with -lutil have (and need) -lkvm as well, some do not.
  28. # On Solaris, -lkvm requires nlist from -lelf, so check that first
  29. # to get the right answer into the cache.
  30. # For kstat on solaris, we need libelf to force the definition of SVR4 below.
  31. if test $gl_have_func = no; then
  32. AC_CHECK_LIB(elf, elf_begin, LIBS="-lelf $LIBS")
  33. fi
  34. if test $gl_have_func = no; then
  35. AC_CHECK_LIB(kvm, kvm_open, LIBS="-lkvm $LIBS")
  36. # Check for the 4.4BSD definition of getloadavg.
  37. AC_CHECK_LIB(util, getloadavg,
  38. [LIBS="-lutil $LIBS" gl_have_func=yes gl_cv_func_getloadavg_setgid=yes])
  39. fi
  40. if test $gl_have_func = no; then
  41. # There is a commonly available library for RS/6000 AIX.
  42. # Since it is not a standard part of AIX, it might be installed locally.
  43. gl_getloadavg_LIBS=$LIBS
  44. LIBS="-L/usr/local/lib $LIBS"
  45. AC_CHECK_LIB(getloadavg, getloadavg,
  46. [LIBS="-lgetloadavg $LIBS"], [LIBS=$gl_getloadavg_LIBS])
  47. fi
  48. # Make sure it is really in the library, if we think we found it,
  49. # otherwise set up the replacement function.
  50. AC_CHECK_FUNCS(getloadavg, [],
  51. [gl_PREREQ_GETLOADAVG])
  52. # Some definitions of getloadavg require that the program be installed setgid.
  53. AC_CACHE_CHECK(whether getloadavg requires setgid,
  54. gl_cv_func_getloadavg_setgid,
  55. [AC_EGREP_CPP([Yowza Am I SETGID yet],
  56. [#define CONFIGURING_GETLOADAVG
  57. #include "$srcdir/$1/getloadavg.c"
  58. #ifdef LDAV_PRIVILEGED
  59. Yowza Am I SETGID yet
  60. #endif
  61. ],
  62. gl_cv_func_getloadavg_setgid=yes,
  63. gl_cv_func_getloadavg_setgid=no)])
  64. if test $gl_cv_func_getloadavg_setgid = yes; then
  65. NEED_SETGID=true
  66. AC_DEFINE(GETLOADAVG_PRIVILEGED, 1,
  67. [Define to 1 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 $gl_cv_func_getloadavg_setgid = yes; then
  74. AC_CACHE_CHECK(group of /dev/kmem, gl_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. gl_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, $gl_cv_group_kmem)dnl
  85. fi
  86. if test "x$gl_save_LIBS" = x; then
  87. GETLOADAVG_LIBS=$LIBS
  88. else
  89. GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$gl_save_LIBS!!"`
  90. fi
  91. LIBS=$gl_save_LIBS
  92. AC_SUBST(GETLOADAVG_LIBS)dnl
  93. ])# gl_GETLOADAVG
  94. # gl_PREREQ_GETLOADAVG
  95. # --------------------
  96. # Set up the AC_LIBOBJ replacement of `getloadavg'.
  97. AC_DEFUN([gl_PREREQ_GETLOADAVG],
  98. [AC_LIBOBJ(getloadavg)
  99. AC_DEFINE(C_GETLOADAVG, 1, [Define to 1 if using `getloadavg.c'.])
  100. # Figure out what our getloadavg.c needs.
  101. gl_have_func=no
  102. AC_CHECK_HEADER(sys/dg_sys_info.h,
  103. [gl_have_func=yes
  104. AC_DEFINE(DGUX, 1, [Define to 1 for DGUX with <sys/dg_sys_info.h>.])
  105. AC_CHECK_LIB(dgc, dg_sys_info)])
  106. # We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
  107. # uses stabs), but it is still SVR4. We cannot check for <elf.h> because
  108. # Irix 4.0.5F has the header but not the library.
  109. if test $gl_have_func = no && test "$ac_cv_lib_elf_elf_begin" = yes; then
  110. gl_have_func=yes
  111. AC_DEFINE(SVR4, 1, [Define to 1 on System V Release 4.])
  112. fi
  113. if test $gl_have_func = no; then
  114. AC_CHECK_HEADER(inq_stats/cpustats.h,
  115. [gl_have_func=yes
  116. AC_DEFINE(UMAX, 1, [Define to 1 for Encore UMAX.])
  117. AC_DEFINE(UMAX4_3, 1,
  118. [Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h>
  119. instead of <sys/cpustats.h>.])])
  120. fi
  121. if test $gl_have_func = no; then
  122. AC_CHECK_HEADER(sys/cpustats.h,
  123. [gl_have_func=yes; AC_DEFINE(UMAX)])
  124. fi
  125. if test $gl_have_func = no; then
  126. AC_CHECK_HEADERS(mach/mach.h)
  127. fi
  128. AC_CHECK_HEADERS(nlist.h,
  129. [AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
  130. [AC_DEFINE(NLIST_NAME_UNION, 1,
  131. [Define to 1 if your `struct nlist' has an
  132. `n_un' member. Obsolete, depend on
  133. `HAVE_STRUCT_NLIST_N_UN_N_NAME])], [],
  134. [@%:@include <nlist.h>])
  135. ])dnl
  136. ])# gl_PREREQ_GETLOADAVG