aboutsummaryrefslogtreecommitdiff
path: root/contrib/ntp/libntp/syssignal.c
diff options
context:
space:
mode:
authorOllivier Robert <roberto@FreeBSD.org>1999-12-09 13:01:21 +0000
committerOllivier Robert <roberto@FreeBSD.org>1999-12-09 13:01:21 +0000
commitc0b746e5e8d9479f05b3749cbf1f73b8928719bd (patch)
treefc0cfa1aab0ff6b228f511b410733ef4f35d1ead /contrib/ntp/libntp/syssignal.c
downloadsrc-c0b746e5e8d9479f05b3749cbf1f73b8928719bd.tar.gz
src-c0b746e5e8d9479f05b3749cbf1f73b8928719bd.zip
Virgin import of ntpd 4.0.98fvendor/ntp/4.0.98f
Notes
Notes: svn path=/vendor/ntp/dist/; revision=54359 svn path=/vendor/ntp/4.0.98f/; revision=54361; tag=vendor/ntp/4.0.98f
Diffstat (limited to 'contrib/ntp/libntp/syssignal.c')
-rw-r--r--contrib/ntp/libntp/syssignal.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/contrib/ntp/libntp/syssignal.c b/contrib/ntp/libntp/syssignal.c
new file mode 100644
index 000000000000..50c65b7c3d11
--- /dev/null
+++ b/contrib/ntp/libntp/syssignal.c
@@ -0,0 +1,123 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <signal.h>
+
+#include "ntp_syslog.h"
+#include "ntp_stdlib.h"
+
+#ifdef HAVE_SIGACTION
+
+void
+signal_no_reset(
+#if defined(__STDC__) || defined(HAVE_STDARG_H)
+ int sig,
+ void (*func) (int)
+#else
+ sig, func
+#endif
+ )
+#if defined(__STDC__) || defined(HAVE_STDARG_H)
+#else
+ int sig;
+ void (*func) P((int));
+#endif
+{
+ int n;
+ struct sigaction vec;
+
+ vec.sa_handler = func;
+ sigemptyset(&vec.sa_mask);
+#if 0
+#ifdef SA_RESTART
+ vec.sa_flags = SA_RESTART;
+#else
+ vec.sa_flags = 0;
+#endif
+#else
+ vec.sa_flags = 0;
+#endif
+
+ while (1)
+ {
+ struct sigaction ovec;
+
+ n = sigaction(sig, &vec, &ovec);
+ if (n == -1 && errno == EINTR) continue;
+ if (ovec.sa_flags
+#ifdef SA_RESTART
+ && ovec.sa_flags != SA_RESTART
+#endif
+ )
+ msyslog(LOG_DEBUG, "signal_no_reset: signal %d had flags %x",
+ sig, ovec.sa_flags);
+ break;
+ }
+ if (n == -1) {
+ perror("sigaction");
+ exit(1);
+ }
+}
+
+#elif HAVE_SIGVEC
+
+void
+signal_no_reset(
+ int sig,
+ RETSIGTYPE (*func) (int)
+ )
+{
+ struct sigvec sv;
+ int n;
+
+ bzero((char *) &sv, sizeof(sv));
+ sv.sv_handler = func;
+ n = sigvec(sig, &sv, (struct sigvec *)NULL);
+ if (n == -1) {
+ perror("sigvec");
+ exit(1);
+ }
+}
+
+#elif HAVE_SIGSET
+
+void
+signal_no_reset(
+ int sig,
+ RETSIGTYPE (*func) (int)
+ )
+{
+ int n;
+
+ n = sigset(sig, func);
+ if (n == -1) {
+ perror("sigset");
+ exit(1);
+ }
+}
+
+#else
+
+/* Beware! This implementation resets the signal to SIG_DFL */
+void
+signal_no_reset(
+ int sig,
+ RETSIGTYPE (*func) (int)
+ )
+{
+#ifdef SIG_ERR
+ if (SIG_ERR == signal(sig, func)) {
+#else
+ int n;
+ n = signal(sig, func);
+ if (n == -1) {
+#endif
+ perror("signal");
+ exit(1);
+ }
+}
+
+#endif