xref: /freebsd/contrib/kyua/m4/signals.m4 (revision cc68614da8232d8baaca0ae0d0dd8f890f06623e)
1dnl Copyright 2010 The Kyua Authors.
2dnl All rights reserved.
3dnl
4dnl Redistribution and use in source and binary forms, with or without
5dnl modification, are permitted provided that the following conditions are
6dnl met:
7dnl
8dnl * Redistributions of source code must retain the above copyright
9dnl   notice, this list of conditions and the following disclaimer.
10dnl * Redistributions in binary form must reproduce the above copyright
11dnl   notice, this list of conditions and the following disclaimer in the
12dnl   documentation and/or other materials provided with the distribution.
13dnl * Neither the name of Google Inc. nor the names of its contributors
14dnl   may be used to endorse or promote products derived from this software
15dnl   without specific prior written permission.
16dnl
17dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21dnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23dnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24dnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25dnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26dnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27dnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29dnl
30dnl KYUA_LAST_SIGNO
31dnl
32dnl Detect the last valid signal number.
33dnl
34AC_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])
93