getloadavg.m4 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. # Some systems with -lutil have (and need) -lkvm as well, some do not.
  25. # On Solaris, -lkvm requires nlist from -lelf, so check that first
  26. # to get the right answer into the cache.
  27. # For kstat on solaris, we need libelf to force the definition of SVR4 below.
  28. if test $gl_have_func = no; then
  29. AC_CHECK_LIB(elf, elf_begin, LIBS="-lelf $LIBS")
  30. fi
  31. if test $gl_have_func = no; then
  32. AC_CHECK_LIB(kvm, kvm_open, LIBS="-lkvm $LIBS")
  33. # Check for the 4.4BSD definition of getloadavg.
  34. AC_CHECK_LIB(util, getloadavg,
  35. [LIBS="-lutil $LIBS" gl_have_func=yes gl_cv_func_getloadavg_setgid=yes])
  36. fi
  37. if test $gl_have_func = no; then
  38. # There is a commonly available library for RS/6000 AIX.
  39. # Since it is not a standard part of AIX, it might be installed locally.
  40. gl_getloadavg_LIBS=$LIBS
  41. LIBS="-L/usr/local/lib $LIBS"
  42. AC_CHECK_LIB(getloadavg, getloadavg,
  43. [LIBS="-lgetloadavg $LIBS"], [LIBS=$gl_getloadavg_LIBS])
  44. fi
  45. # Make sure it is really in the library, if we think we found it,
  46. # otherwise set up the replacement function.
  47. AC_CHECK_FUNCS(getloadavg, [],
  48. [gl_PREREQ_GETLOADAVG])
  49. # Some definitions of getloadavg require that the program be installed setgid.
  50. AC_CACHE_CHECK(whether getloadavg requires setgid,
  51. gl_cv_func_getloadavg_setgid,
  52. [AC_EGREP_CPP([Yowza Am I SETGID yet],
  53. [#define CONFIGURING_GETLOADAVG
  54. #include "$srcdir/$1/getloadavg.c"
  55. #ifdef LDAV_PRIVILEGED
  56. Yowza Am I SETGID yet
  57. #endif
  58. ],
  59. gl_cv_func_getloadavg_setgid=yes,
  60. gl_cv_func_getloadavg_setgid=no)])
  61. if test $gl_cv_func_getloadavg_setgid = yes; then
  62. NEED_SETGID=true
  63. AC_DEFINE(GETLOADAVG_PRIVILEGED, 1,
  64. [Define to 1 if the `getloadavg' function needs to be run setuid
  65. or setgid.])
  66. else
  67. NEED_SETGID=false
  68. fi
  69. AC_SUBST(NEED_SETGID)dnl
  70. if test $gl_cv_func_getloadavg_setgid = yes; then
  71. AC_CACHE_CHECK(group of /dev/kmem, gl_cv_group_kmem,
  72. [ # On Solaris, /dev/kmem is a symlink. Get info on the real file.
  73. ac_ls_output=`ls -lgL /dev/kmem 2>/dev/null`
  74. # If we got an error (system does not support symlinks), try without -L.
  75. test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem`
  76. gl_cv_group_kmem=`echo $ac_ls_output \
  77. | sed -ne ['s/[ ][ ]*/ /g
  78. s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\) *.*/\1/
  79. / /s/.* //;p']`
  80. ])
  81. AC_SUBST(KMEM_GROUP, $gl_cv_group_kmem)dnl
  82. fi
  83. if test "x$gl_save_LIBS" = x; then
  84. GETLOADAVG_LIBS=$LIBS
  85. else
  86. GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$gl_save_LIBS!!"`
  87. fi
  88. LIBS=$gl_save_LIBS
  89. AC_SUBST(GETLOADAVG_LIBS)dnl
  90. ])# gl_GETLOADAVG
  91. # gl_PREREQ_GETLOADAVG
  92. # --------------------
  93. # Set up the AC_LIBOBJ replacement of `getloadavg'.
  94. AC_DEFUN([gl_PREREQ_GETLOADAVG],
  95. [AC_LIBOBJ(getloadavg)
  96. AC_DEFINE(C_GETLOADAVG, 1, [Define to 1 if using `getloadavg.c'.])
  97. # Figure out what our getloadavg.c needs.
  98. gl_have_func=no
  99. AC_CHECK_HEADER(sys/dg_sys_info.h,
  100. [gl_have_func=yes
  101. AC_DEFINE(DGUX, 1, [Define to 1 for DGUX with <sys/dg_sys_info.h>.])
  102. AC_CHECK_LIB(dgc, dg_sys_info)])
  103. # We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
  104. # uses stabs), but it is still SVR4. We cannot check for <elf.h> because
  105. # Irix 4.0.5F has the header but not the library.
  106. if test $gl_have_func = no && test "$ac_cv_lib_elf_elf_begin" = yes; then
  107. gl_have_func=yes
  108. AC_DEFINE(SVR4, 1, [Define to 1 on System V Release 4.])
  109. fi
  110. if test $gl_have_func = no; then
  111. AC_CHECK_HEADER(inq_stats/cpustats.h,
  112. [gl_have_func=yes
  113. AC_DEFINE(UMAX, 1, [Define to 1 for Encore UMAX.])
  114. AC_DEFINE(UMAX4_3, 1,
  115. [Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h>
  116. instead of <sys/cpustats.h>.])])
  117. fi
  118. if test $gl_have_func = no; then
  119. AC_CHECK_HEADER(sys/cpustats.h,
  120. [gl_have_func=yes; AC_DEFINE(UMAX)])
  121. fi
  122. if test $gl_have_func = no; then
  123. AC_CHECK_HEADERS(mach/mach.h)
  124. fi
  125. AC_CHECK_HEADERS(nlist.h,
  126. [AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
  127. [AC_DEFINE(NLIST_NAME_UNION, 1,
  128. [Define to 1 if your `struct nlist' has an
  129. `n_un' member. Obsolete, depend on
  130. `HAVE_STRUCT_NLIST_N_UN_N_NAME])], [],
  131. [@%:@include <nlist.h>])
  132. ])dnl
  133. ])# gl_PREREQ_GETLOADAVG