Debian Codegraph @

autoconf-macros/ax_nagios_get_init

raw
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
53 AU_ALIAS([AC_NAGIOS_GET_INIT], [AX_NAGIOS_GET_INIT])
54 AC_DEFUN([AX_NAGIOS_GET_INIT],
55 [
56
57 AC_SUBST(init_type)
58
59 #
60 # Get user hints for possible cross-compile
61 #
62 AC_MSG_CHECKING(what init system is being used )
63 AC_ARG_WITH(init_type,AS_HELP_STRING([--with-init-type=type],
64 [specify init type (bsd, sysv, systemd, launchd, smf10, smf11, upstart,
65 openrc, etc.)]),
66 [
67 #
68 # Run this if --with was specified
69 #
70 if test "x$withval" = x -o x$withval = xno; then
71 init_type_wanted=yes
72 else
73 init_type_wanted=no
74 init_type="$withval"
75 AC_MSG_RESULT($init_type)
76 fi
77 ], [
78 #
79 # Run this if --with was not specified
80 #
81 init_type_wanted=yes
82 ])
83
84 if test x$init_type = xno; then
85 init_type_wanted=yes
86 elif test x$init_type = xyes; then
87 AC_MSG_ERROR([you must enter an init type if '--with-init-type' is specified])
88 fi
89
90 #
91 # Determine init type if it wasn't supplied
92 #
93 if test $init_type_wanted = yes; then
94 init_type=""
95
96 if test x"$opsys" = x; then
97 init_type="unknown"
98 init_type_wanted=no
99 elif test x"$dist_type" = x; then
100 init_type="unknown"
101 init_type_wanted=no
102 elif test "$opsys" = "osx"; then
103 init_type="launchd"
104 init_type_wanted=no
105 elif test "$opsys" = "bsd"; then
106 init_type="newbsd"
107 init_type_wanted=no
108 elif test "$dist_type" = "solaris"; then
109 if test -d "/lib/svc/manifest"; then
110 init_type="smf11"
111 init_type_wanted=no
112 elif test -d "/lib/svc/monitor"; then
113 init_type="smf10"
114 init_type_wanted=no
115 else
116 init_type="sysv"
117 init_type_wanted=no
118 fi
119 elif test "$dist_type" = "slackware"; then
120 init_type="bsd"
121 init_type_wanted=no
122 elif test "$dist_type" = "aix"; then
123 init_type="bsd"
124 init_type_wanted=no
125 elif test "$dist_type" = "hp-ux"; then
126 init_type="unknown"
127 init_type_wanted=no
128 fi
129 fi
130
131 PSCMD="ps -p1 -o args"
132 if test $dist_type = solaris; then
133 PSCMD="env UNIX95=1; ps -p1 -o args"
134 fi
135
136 if test "$init_type_wanted" = yes; then
137 pid1=`$PSCMD | grep -vi COMMAND | cut -d' ' -f1`
138 if test x"$pid1" = "x"; then
139 init_type="unknown"
140 init_type_wanted=no
141 fi
142 if `echo $pid1 | grep "systemd" > /dev/null`; then
143 init_type="systemd"
144 init_type_wanted=no
145 fi
146
147 if test "$init_type_wanted" = yes; then
148 if test "$pid1" = "init"; then
149 if test -e "/sbin/init"; then
150 pid1="/sbin/init";
151 elif test -e "/usr/sbin/init"; then
152 pid1="/usr/sbin/init"
153 else
154 init_type="unknown"
155 init_type_wanted=no
156 fi
157 fi
158 if test -L "$pid1"; then
159 pid1=`readlink "$pid1"`
160 fi
161 fi
162
163 if test "$init_type_wanted" = yes; then
164 if `echo $pid1 | grep "systemd" > /dev/null`; then
165 init_type="systemd"
166 init_type_wanted=no
167 elif test -f "/sbin/rc"; then
168 if test -f /sbin/runscript; then
169 init_type_wanted=no
170 if `/sbin/start-stop-daemon -V | grep "OpenRC" > /dev/null`; then
171 init_type="openrc"
172 else
173 init_type="gentoo"
174 fi
175 fi
176 fi
177 fi
178
179 if test "$init_type_wanted" = yes; then
180 if test "$pid1" = "/sbin/init" -o "$pid1" = "/usr/sbin/init"; then
181 if `$pid1 --version 2>/dev/null | grep "upstart" >/dev/null`; then
182 init_type="upstart"
183 init_type_wanted=no
184 elif test -f "/etc/rc" -a ! -L "/etc/rc"; then
185 init_type="newbsd"
186 init_type_wanted=no
187 else
188 init_type="sysv"
189 init_type_wanted=no
190 fi
191 fi
192 fi
193
194 if test "$init_type_wanted" = yes; then
195 init_type="unknown"
196 fi
197 fi
198
199 AC_MSG_RESULT($init_type)
200 ])