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 14 void 15 signal_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 while (1) 45 { 46 struct sigaction ovec; 47 48 n = sigaction(sig, &vec, &ovec); 49 if (n == -1 && errno == EINTR) continue; 50 if (ovec.sa_flags 51 #ifdef SA_RESTART 52 && ovec.sa_flags != SA_RESTART 53 #endif 54 ) 55 msyslog(LOG_DEBUG, "signal_no_reset: signal %d had flags %x", 56 sig, ovec.sa_flags); 57 break; 58 } 59 if (n == -1) { 60 perror("sigaction"); 61 exit(1); 62 } 63 } 64 65 #elif HAVE_SIGVEC 66 67 void 68 signal_no_reset( 69 int sig, 70 RETSIGTYPE (*func) (int) 71 ) 72 { 73 struct sigvec sv; 74 int n; 75 76 bzero((char *) &sv, sizeof(sv)); 77 sv.sv_handler = func; 78 n = sigvec(sig, &sv, (struct sigvec *)NULL); 79 if (n == -1) { 80 perror("sigvec"); 81 exit(1); 82 } 83 } 84 85 #elif HAVE_SIGSET 86 87 void 88 signal_no_reset( 89 int sig, 90 RETSIGTYPE (*func) (int) 91 ) 92 { 93 int n; 94 95 n = sigset(sig, func); 96 if (n == -1) { 97 perror("sigset"); 98 exit(1); 99 } 100 } 101 102 #else 103 104 /* Beware! This implementation resets the signal to SIG_DFL */ 105 void 106 signal_no_reset( 107 int sig, 108 RETSIGTYPE (*func) (int) 109 ) 110 { 111 #ifdef SIG_ERR 112 if (SIG_ERR == signal(sig, func)) { 113 #else 114 int n; 115 n = signal(sig, func); 116 if (n == -1) { 117 #endif 118 perror("signal"); 119 exit(1); 120 } 121 } 122 123 #endif 124