add simple test for command()
[nsca-ng.git] / m4 / pidfile.m4
blob70e908a6ad35cc964c916fcc650897a996580a0e
1 # Copyright (c) 2013 Holger Weiss <holger@weiss.in-berlin.de>
2 # All rights reserved.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
7 # 1. Redistributions of source code must retain the above copyright notice, this
8 #    list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright notice,
11 #    this list of conditions and the following disclaimer in the documentation
12 #    and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 # DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 # NSCA_LIB_PIDFILE
26 # ----------------
27 # Check the availability of FreeBSD's pidfile(3) API (which is also available on
28 # some Linux systems).  If it's found, we set $nsca_lib_pidfile_embedded to "no"
29 # and arrange for using the library which provides the API.  Otherwise, we set
30 # $nsca_lib_pidfile_embedded to "yes" and arrange for using the bundled
31 # replacement functions.
32 AC_DEFUN([NSCA_LIB_PIDFILE],
34   AC_CHECK_HEADERS([sys/param.h])
35   AC_CHECK_HEADERS([bsd/libutil.h libutil.h],
36     [AC_CHECK_FUNC([pidfile_open],
37       [nsca_lib_pidfile_embedded=no],
38       [AC_CHECK_LIB([bsd], [pidfile_open],
39         [PIDFILELIBS='-lbsd'
40          nsca_lib_pidfile_embedded=no],
41         [AC_CHECK_LIB([util], [pidfile_open],
42           [PIDFILELIBS='-lutil'
43            nsca_lib_pidfile_embedded=no],
44           [nsca_lib_pidfile_embedded=yes])])])
45      break],
46     [nsca_lib_pidfile_embedded=yes],
47     [[#if HAVE_SYS_PARAM_H
48       #include <sys/param.h>
49       #endif]])
50   AS_IF([test "x$nsca_lib_pidfile_embedded" = xyes],
51     [_NSCA_LIB_PIDFILE_EMBEDDED])
52   AC_SUBST([PIDFILELIBS])
53 ])# NSCA_LIB_PIDFILE
55 # _NSCA_LIB_PIDFILE_EMBEDDED
56 # --------------------------
57 # Arrange for using the bundled pidfile functions.  If the flock(2) function is
58 # found, we set $nsca_func_flock to "yes"; otherwise, we set that variable to
59 # "no".
60 AC_DEFUN([_NSCA_LIB_PIDFILE_EMBEDDED],
62   AC_CHECK_HEADERS([sys/file.h])
63   AC_TYPE_MODE_T
64   # At least on AIX 5.3, flock(2) is hidden in libbsd.
65   AC_CHECK_FUNC([flock],
66     [nsca_func_flock=yes],
67     [AC_CHECK_LIB([bsd], [flock],
68       [PIDFILELIBS='-lbsd'
69        nsca_func_flock=yes],
70       [nsca_func_flock=no])])
71   AS_IF([test "x$nsca_func_flock" = xyes],
72     [AC_DEFINE([HAVE_FLOCK], [1],
73       [Define to 1 if you have the `flock' function.])])
74 ])# _NSCA_LIB_PIDFILE_EMBEDDED
76 dnl vim:set joinspaces textwidth=80: