summaryrefslogtreecommitdiffstats
path: root/aclocal/bsdsignals.m4
blob: 362ddb5bd3bff5939657066c9ff97a94ac98a899 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
dnl *********** BSD vs. POSIX signal handling **************
AC_DEFUN([AC_BSD_SIGNALS], [
  AC_MSG_CHECKING(for BSD signal semantics)
  AC_CACHE_VAL(knfsd_cv_bsd_signals,
    [AC_RUN_IFELSE([AC_LANG_SOURCE([[
	#include <signal.h>
	#include <unistd.h>
	#include <sys/wait.h>

	static int counter = 0;
	static void handler(int num) { counter++; }

	int main()
	{
		int	s;
		if ((s = fork()) < 0) return 1;
		if (s != 0) {
			if (wait(&s) < 0) return 1;
			return WIFSIGNALED(s)? 1 : 0;
		}

		signal(SIGHUP, handler);
		kill(getpid(), SIGHUP); kill(getpid(), SIGHUP);
		return (counter == 2)? 0 : 1;
	}
    ]])],[knfsd_cv_bsd_signals=yes],[knfsd_cv_bsd_signals=no],[
      case "$host_os" in
        *linux*) knfsd_cv_bsd_signals=no;;
        *bsd*)   knfsd_cv_bsd_signals=yes;;
        *)       AC_MSG_ERROR([unable to guess signal semantics for $host_os; please set knfsd_cv_bsd_signals]);;
      esac
    ])]) dnl
    AC_MSG_RESULT($knfsd_cv_bsd_signals)
    test $knfsd_cv_bsd_signals = yes && AC_DEFINE(HAVE_BSD_SIGNALS, 1, [Define this if you want to use BSD signal semantics])
])dnl