PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/ntp/libntp/syssignal.c

https://bitbucket.org/freebsd/freebsd-head/
C | 133 lines | 114 code | 17 blank | 2 comment | 24 complexity | 3aae6710449b7bd99f3bc748f8f2da73 MD5 | raw file
  1#ifdef HAVE_CONFIG_H
  2# include <config.h>
  3#endif
  4
  5#include <stdio.h>
  6#include <sys/types.h>
  7#include <signal.h>
  8
  9#include "ntp_syslog.h"
 10#include "ntp_stdlib.h"
 11
 12#ifdef HAVE_SIGACTION
 13
 14void
 15signal_no_reset(
 16#if defined(__STDC__) || defined(HAVE_STDARG_H)
 17	int sig,
 18	void (*func) (int)
 19#else
 20	sig, func
 21#endif
 22	)
 23#if defined(__STDC__) || defined(HAVE_STDARG_H)
 24#else
 25	 int sig;
 26	 void (*func) P((int));
 27#endif
 28{
 29	int n;
 30	struct sigaction vec;
 31
 32	vec.sa_handler = func;
 33	sigemptyset(&vec.sa_mask);
 34#if 0
 35#ifdef SA_RESTART
 36	vec.sa_flags = SA_RESTART;
 37#else
 38	vec.sa_flags = 0;
 39#endif
 40#else
 41	vec.sa_flags = 0;
 42#endif
 43
 44#ifdef SA_RESTART
 45/* Added for PPS clocks on Solaris 7 which get EINTR errors */
 46# ifdef SIGPOLL
 47	if (sig == SIGPOLL) vec.sa_flags = SA_RESTART;
 48# endif
 49# ifdef SIGIO
 50	if (sig == SIGIO)   vec.sa_flags = SA_RESTART;
 51# endif
 52#endif
 53
 54	while (1)
 55	{
 56		struct sigaction ovec;
 57
 58		n = sigaction(sig, &vec, &ovec);
 59		if (n == -1 && errno == EINTR) continue;
 60		if (ovec.sa_flags
 61#ifdef	SA_RESTART
 62		    && ovec.sa_flags != SA_RESTART
 63#endif
 64		    )
 65			msyslog(LOG_DEBUG, "signal_no_reset: signal %d had flags %x",
 66				sig, ovec.sa_flags);
 67		break;
 68	}
 69	if (n == -1) {
 70		perror("sigaction");
 71		exit(1);
 72	}
 73}
 74
 75#elif  HAVE_SIGVEC
 76
 77void
 78signal_no_reset(
 79	int sig,
 80	RETSIGTYPE (*func) (int)
 81	)
 82{
 83	struct sigvec sv;
 84	int n;
 85
 86	bzero((char *) &sv, sizeof(sv));
 87	sv.sv_handler = func;
 88	n = sigvec(sig, &sv, (struct sigvec *)NULL);
 89	if (n == -1) {
 90		perror("sigvec");
 91		exit(1);
 92	}
 93}
 94
 95#elif  HAVE_SIGSET
 96
 97void
 98signal_no_reset(
 99	int sig,
100	RETSIGTYPE (*func) (int)
101	)
102{
103	int n;
104
105	n = sigset(sig, func);
106	if (n == -1) {
107		perror("sigset");
108		exit(1);
109	}
110}
111
112#else
113
114/* Beware!	This implementation resets the signal to SIG_DFL */
115void
116signal_no_reset(
117	int sig,
118	RETSIGTYPE (*func) (int)
119	)
120{
121#ifdef SIG_ERR
122	if (SIG_ERR == signal(sig, func)) {
123#else
124	int n;
125	n = signal(sig, func);
126	if (n == -1) {
127#endif
128		perror("signal");
129		exit(1);
130	}
131}
132
133#endif