ax_nagios_get_init.m4 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. # ===========================================================================
  2. # SYNOPSIS
  3. #
  4. # AX_NAGIOS_GET_INIT
  5. #
  6. # DESCRIPTION
  7. #
  8. # This macro determines the O/S distribution of the computer it is run on.
  9. # $init_type will be set and will be one of:
  10. # unknown (could not be determined)
  11. # launchd (Mac OS X)
  12. # bsd (Slackware Linux)
  13. # newbsd (FreeBSD, OpenBSD, NetBSD, Dragonfly, etc)
  14. # smf10 (Solaris)
  15. # smf11 (Solaris)
  16. # systemd (Linux SystemD)
  17. # gentoo (Older Gentoo)
  18. # openrc (Recent Gentoo and some others)
  19. # upstart (Older Debian)
  20. # sysv (The rest)
  21. #
  22. # LICENSE
  23. #
  24. # Copyright (c) 2016 Nagios Core Development Team
  25. #
  26. # This program is free software; you can redistribute it and/or modify it
  27. # under the terms of the GNU General Public License as published by the
  28. # Free Software Foundation; either version 2 of the License, or (at your
  29. # option) any later version.
  30. #
  31. # This program is distributed in the hope that it will be useful, but
  32. # WITHOUT ANY WARRANTY; without even the implied warranty of
  33. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  34. # Public License for more details.
  35. #
  36. # You should have received a copy of the GNU General Public License along
  37. # with this program. If not, see <http://www.gnu.org/licenses/>.
  38. #
  39. # As a special exception, the respective Autoconf Macro's copyright owner
  40. # gives unlimited permission to copy, distribute and modify the configure
  41. # scripts that are the output of Autoconf when processing the Macro. You
  42. # need not follow the terms of the GNU General Public License when using
  43. # or distributing such scripts, even though portions of the text of the
  44. # Macro appear in them. The GNU General Public License (GPL) does govern
  45. # all other use of the material that constitutes the Autoconf Macro.
  46. #
  47. # This special exception to the GPL applies to versions of the Autoconf
  48. # Macro released by the Autoconf Archive. When you make and distribute a
  49. # modified version of the Autoconf Macro, you may extend this special
  50. # exception to the GPL to apply to your modified version as well.
  51. # ===========================================================================
  52. AC_DEFUN([AX_NAGIOS_GET_INIT],
  53. [
  54. AC_SUBST(init_type)
  55. #
  56. # Get user hints for possible cross-compile
  57. #
  58. AC_MSG_CHECKING(what init system is being used )
  59. AC_ARG_WITH(init_type,AS_HELP_STRING([--with-init-type=type],[specify init type (bsd, sysv, systemd, launchd, smf10, smf11, upstart,
  60. openrc, etc.)]),
  61. [
  62. #
  63. # Run this if --with was specified
  64. #
  65. if test "x$withval" = x -o x$withval = xno; then
  66. init_type_wanted=yes
  67. else
  68. init_type_wanted=no
  69. init_type="$withval"
  70. AC_MSG_RESULT($init_type)
  71. fi
  72. ], [
  73. #
  74. # Run this if --with was not specified
  75. #
  76. init_type_wanted=yes
  77. ])
  78. if test x$init_type = xno; then
  79. init_type_wanted=yes
  80. elif test x$init_type = xyes; then
  81. AC_MSG_ERROR([you must enter an init type if '--with-init-type' is specified])
  82. fi
  83. #
  84. # Determine init type if it wasn't supplied
  85. #
  86. if test $init_type_wanted = yes; then
  87. init_type=""
  88. if test x"$opsys" = x; then
  89. init_type="unknown"
  90. init_type_wanted=no
  91. elif test x"$dist_type" = x; then
  92. init_type="unknown"
  93. init_type_wanted=no
  94. elif test "$opsys" = "osx"; then
  95. init_type="launchd"
  96. init_type_wanted=no
  97. elif test "$opsys" = "bsd"; then
  98. init_type="newbsd"
  99. init_type_wanted=no
  100. elif test "$dist_type" = "solaris"; then
  101. if test -d "/lib/svc/manifest"; then
  102. init_type="smf11"
  103. init_type_wanted=no
  104. elif test -d "/lib/svc/monitor"; then
  105. init_type="smf10"
  106. init_type_wanted=no
  107. else
  108. init_type="sysv"
  109. init_type_wanted=no
  110. fi
  111. elif test "$dist_type" = "slackware"; then
  112. init_type="bsd"
  113. init_type_wanted=no
  114. elif test "$dist_type" = "aix"; then
  115. init_type="bsd"
  116. init_type_wanted=no
  117. elif test "$dist_type" = "hp-ux"; then
  118. init_type="unknown"
  119. init_type_wanted=no
  120. fi
  121. fi
  122. PSCMD="ps -p1 -o args"
  123. if test $dist_type = solaris; then
  124. PSCMD="env UNIX95=1; ps -p1 -o args"
  125. fi
  126. if test "$init_type_wanted" = yes; then
  127. pid1=`$PSCMD | grep -vi COMMAND | cut -d' ' -f1`
  128. if test x"$pid1" = "x"; then
  129. init_type="unknown"
  130. init_type_wanted=no
  131. fi
  132. if `echo $pid1 | grep "systemd" > /dev/null`; then
  133. init_type="systemd"
  134. init_type_wanted=no
  135. fi
  136. if test "$init_type_wanted" = yes; then
  137. if test "$pid1" = "init"; then
  138. if test -e "/sbin/init"; then
  139. pid1="/sbin/init";
  140. elif test -e "/usr/sbin/init"; then
  141. pid1="/usr/sbin/init"
  142. else
  143. init_type="unknown"
  144. init_type_wanted=no
  145. fi
  146. fi
  147. if test -L "$pid1"; then
  148. pid1=`readlink "$pid1"`
  149. fi
  150. fi
  151. if test "$init_type_wanted" = yes; then
  152. if `echo $pid1 | grep "systemd" > /dev/null`; then
  153. init_type="systemd"
  154. init_type_wanted=no
  155. elif test -f "/sbin/rc"; then
  156. if test -f /sbin/runscript; then
  157. init_type_wanted=no
  158. if `/sbin/start-stop-daemon -V | grep "OpenRC" > /dev/null`; then
  159. init_type="openrc"
  160. else
  161. init_type="gentoo"
  162. fi
  163. fi
  164. fi
  165. fi
  166. if test "$init_type_wanted" = yes; then
  167. if test "$pid1" = "/sbin/init" -o "$pid1" = "/usr/sbin/init"; then
  168. if `$pid1 --version 2>/dev/null | grep "upstart" >/dev/null`; then
  169. init_type="upstart"
  170. init_type_wanted=no
  171. elif test -f "/etc/rc" -a ! -L "/etc/rc"; then
  172. init_type="newbsd"
  173. init_type_wanted=no
  174. else
  175. init_type="sysv"
  176. init_type_wanted=no
  177. fi
  178. fi
  179. fi
  180. if test "$init_type_wanted" = yes; then
  181. init_type="unknown"
  182. fi
  183. fi
  184. AC_MSG_RESULT($init_type)
  185. ])