Sync usage with man page.
[netbsd-mini2440.git] / dist / ntp / libntp / syssignal.c
blob5b42e83989dde03f3938e10af7cac27cc5ed0ac7
1 /* $NetBSD$ */
3 #ifdef HAVE_CONFIG_H
4 # include <config.h>
5 #endif
7 #include <stdio.h>
8 #include <sys/types.h>
9 #include <signal.h>
11 #include "ntp_syslog.h"
12 #include "ntp_stdlib.h"
14 #ifdef HAVE_SIGACTION
16 void
17 signal_no_reset(
18 #if defined(__STDC__) || defined(HAVE_STDARG_H)
19 int sig,
20 void (*func) (int)
21 #else
22 sig, func
23 #endif
25 #if defined(__STDC__) || defined(HAVE_STDARG_H)
26 #else
27 int sig;
28 void (*func) P((int));
29 #endif
31 int n;
32 struct sigaction vec;
34 vec.sa_handler = func;
35 sigemptyset(&vec.sa_mask);
36 #if 0
37 #ifdef SA_RESTART
38 vec.sa_flags = SA_RESTART;
39 #else
40 vec.sa_flags = 0;
41 #endif
42 #else
43 vec.sa_flags = 0;
44 #endif
46 #ifdef SA_RESTART
47 /* Added for PPS clocks on Solaris 7 which get EINTR errors */
48 # ifdef SIGPOLL
49 if (sig == SIGPOLL) vec.sa_flags = SA_RESTART;
50 # endif
51 # ifdef SIGIO
52 if (sig == SIGIO) vec.sa_flags = SA_RESTART;
53 # endif
54 #endif
56 while (1)
58 struct sigaction ovec;
60 n = sigaction(sig, &vec, &ovec);
61 if (n == -1 && errno == EINTR) continue;
62 if (ovec.sa_flags
63 #ifdef SA_RESTART
64 && ovec.sa_flags != SA_RESTART
65 #endif
67 msyslog(LOG_DEBUG, "signal_no_reset: signal %d had flags %x",
68 sig, ovec.sa_flags);
69 break;
71 if (n == -1) {
72 perror("sigaction");
73 exit(1);
77 #elif HAVE_SIGVEC
79 void
80 signal_no_reset(
81 int sig,
82 RETSIGTYPE (*func) (int)
85 struct sigvec sv;
86 int n;
88 bzero((char *) &sv, sizeof(sv));
89 sv.sv_handler = func;
90 n = sigvec(sig, &sv, (struct sigvec *)NULL);
91 if (n == -1) {
92 perror("sigvec");
93 exit(1);
97 #elif HAVE_SIGSET
99 void
100 signal_no_reset(
101 int sig,
102 RETSIGTYPE (*func) (int)
105 int n;
107 n = sigset(sig, func);
108 if (n == -1) {
109 perror("sigset");
110 exit(1);
114 #else
116 /* Beware! This implementation resets the signal to SIG_DFL */
117 void
118 signal_no_reset(
119 int sig,
120 RETSIGTYPE (*func) (int)
123 #ifdef SIG_ERR
124 if (SIG_ERR == signal(sig, func)) {
125 #else
126 int n;
127 n = signal(sig, func);
128 if (n == -1) {
129 #endif
130 perror("signal");
131 exit(1);
135 #endif