prepare for release
[alioth/jupp.git] / acinclude.m4
1 dnl $MirOS: contrib/code/jupp/acinclude.m4,v 1.4 2018/02/01 02:36:51 tg Exp $
2
3 dnl ------------------
4 dnl Check if setpgrp must have two arguments
5 dnl autoconf-own macro is damaged for *BSD systems
6 dnl ------------------
7 AC_DEFUN([joe_SETPGRP],
8         [AC_CACHE_CHECK([whether setpgrp() takes no arguments],
9                 [joe_cv_setpgrp_void],
10                 [AC_TRY_RUN([
11 #if HAVE_UNISTD_H
12 #include <unistd.h>
13 #endif
14 int main() {
15         /* exit succesfully if setpgrp() takes two args (*BSD systems) */
16         exit(setpgrp(0, 0) != 0);
17 }],
18                         [joe_cv_setpgrp_void=no],
19                         [joe_cv_setpgrp_void=yes],
20                         [joe_cv_setpgrp_void=yes])
21                 ])
22         if test "$joe_cv_setpgrp_void" = yes; then
23                 AC_DEFINE([SETPGRP_VOID], 1, [Define if setpgrp() takes no arguments])
24         fi
25 ])
26
27 dnl ------------------
28 dnl Check to see if signal handlers must be reinstalled when invoked
29 dnl ------------------
30 AC_DEFUN([joe_REINSTALL_SIGHANDLERS],
31         [AC_CACHE_CHECK([whether sighandlers must be reinstalled],
32                 [joe_cv_reinstall_sighandlers],
33                 [AC_TRY_RUN([
34 #if HAVE_UNISTD_H
35 #include <unistd.h>
36 #endif
37 #if HAVE_SIGNAL_H
38 #include <signal.h>
39 #endif
40
41 #ifndef HAVE_SIGHANDLER_T
42 typedef RETSIGTYPE (*sighandler_t)(int);
43 #endif
44
45 int nsigint;
46
47 void set_signal(int signum, sighandler_t handler) {
48 #if HAVE_SIGACTION
49         struct sigaction sact;
50
51         sact.sa_handler = handler;
52         sact.sa_flags = 0;
53         sigemptyset(&sact.sa_mask);
54         sigaction(signum, &sact, NULL);
55 #elif HAVE_SIGVEC
56         struct sigvec svec;
57
58         svec.sv_handler = handler;
59         svec.sv_flags = 0;
60         sigemptyset(&svec.sv_mask);
61         sigvec(signum, &svec, NULL);
62 #else
63         signal(signum, handler);
64 #endif
65 }
66
67 RETSIGTYPE sigint(int s) {
68         nsigint++;
69 }
70
71 int main() {
72         nsigint = 0;
73         set_signal(SIGINT, sigint);
74         kill((int)getpid(), SIGINT);
75         kill((int)getpid(), SIGINT);
76         /* exit succesfully if don't have to reinstall sighandler when invoked */
77         exit(nsigint != 2);
78 }],
79                         [joe_cv_reinstall_sighandlers=no],
80                         [joe_cv_reinstall_sighandlers=yes],
81                         [joe_cv_reinstall_sighandlers=yes])
82                 ])
83         if test "$joe_cv_reinstall_sighandlers" = yes; then
84                 AC_DEFINE([NEED_TO_REINSTALL_SIGNAL], 1, [Define if we have to reinstall signal handler when invoked])
85         fi
86 ])