]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/kyua/m4/signals.m4
sysctl(9): Fix a few mandoc related issues
[FreeBSD/FreeBSD.git] / contrib / kyua / m4 / signals.m4
1 dnl Copyright 2010 The Kyua Authors.
2 dnl All rights reserved.
3 dnl
4 dnl Redistribution and use in source and binary forms, with or without
5 dnl modification, are permitted provided that the following conditions are
6 dnl met:
7 dnl
8 dnl * Redistributions of source code must retain the above copyright
9 dnl   notice, this list of conditions and the following disclaimer.
10 dnl * Redistributions in binary form must reproduce the above copyright
11 dnl   notice, this list of conditions and the following disclaimer in the
12 dnl   documentation and/or other materials provided with the distribution.
13 dnl * Neither the name of Google Inc. nor the names of its contributors
14 dnl   may be used to endorse or promote products derived from this software
15 dnl   without specific prior written permission.
16 dnl
17 dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 dnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 dnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 dnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 dnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 dnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 dnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 dnl
30 dnl KYUA_LAST_SIGNO
31 dnl
32 dnl Detect the last valid signal number.
33 dnl
34 AC_DEFUN([KYUA_LAST_SIGNO], [
35     AC_CACHE_CHECK(
36         [for the last valid signal],
37         [kyua_cv_signals_lastno], [
38         AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <err.h>
39 #include <errno.h>
40 #include <signal.h>
41 #include <stdio.h>
42 #include <stdio.h>
43 #include <stdlib.h>], [
44     static const int max_signals = 256;
45     int i;
46     FILE *f;
47
48     i = 0;
49     while (i < max_signals) {
50         i++;
51         if (i != SIGKILL && i != SIGSTOP) {
52             struct sigaction sa;
53             int ret;
54
55             sa.sa_handler = SIG_DFL;
56             sigemptyset(&sa.sa_mask);
57             sa.sa_flags = 0;
58
59             ret = sigaction(i, &sa, NULL);
60             if (ret == -1) {
61                 warn("sigaction(%d) failed", i);
62                 if (errno == EINVAL) {
63                     i--;
64                     break;
65                 } else
66                     err(EXIT_FAILURE, "sigaction failed");
67             }
68         }
69     }
70     if (i == max_signals)
71         errx(EXIT_FAILURE, "too many signals");
72
73     f = fopen("conftest.cnt", "w");
74     if (f == NULL)
75         err(EXIT_FAILURE, "failed to open file");
76
77     fprintf(f, "%d\n", i);
78     fclose(f);
79
80     return EXIT_SUCCESS;
81 ])],
82         [if test ! -f conftest.cnt; then
83              kyua_cv_signals_lastno=15
84          else
85              kyua_cv_signals_lastno=$(cat conftest.cnt)
86              rm -f conftest.cnt
87          fi],
88         [kyua_cv_signals_lastno=15])
89     ])
90     AC_DEFINE_UNQUOTED([LAST_SIGNO], [${kyua_cv_signals_lastno}],
91                        [Define to the last valid signal number])
92 ])