1 /* $Id: xsignal.c 5610 2002-08-18 22:22:52Z rra $
3 ** A reliable implementation of signal for System V systems.
5 ** Two functions are provided, xsignal and xsignal_norestart. The former
6 ** attempts to set system calls to be restarted and the latter does not.
8 ** Be aware that there's weird declaration stuff going on here; a signal
9 ** handler is a pointer to a function taking an int and returning void.
10 ** We typedef this as sig_handler_type for clearer code.
17 typedef void (*sig_handler_type)(int);
22 xsignal(int signum, sig_handler_type sigfunc)
24 struct sigaction act, oact;
26 act.sa_handler = sigfunc;
27 sigemptyset(&act.sa_mask);
29 /* Try to restart system calls if possible. */
31 act.sa_flags = SA_RESTART;
36 if (sigaction(signum, &act, &oact) < 0)
38 return oact.sa_handler;
42 xsignal_norestart(int signum, sig_handler_type sigfunc)
44 struct sigaction act, oact;
46 act.sa_handler = sigfunc;
47 sigemptyset(&act.sa_mask);
49 /* Try not to restart system calls. */
51 act.sa_flags = SA_INTERRUPT;
56 if (sigaction(signum, &act, &oact) < 0)
58 return oact.sa_handler;
61 #else /* !HAVE_SIGACTION */
64 xsignal(int signum, sig_handler_type sigfunc)
66 return signal(signum, sigfunc);
70 xsignal_norestart(int signum, sig_handler_type sigfunc)
72 return signal(signum, sigfunc);
75 #endif /* !HAVE_SIGACTION */