Date: Thu, 13 Mar 1997 04:45:40 -0800 (PST) From: Brian Somers <brian> To: CVS-committers, cvs-all, cvs-usrsbin Subject: cvs commit: src/usr.sbin/ppp sig.c sig.h Makefile chat.c main.c timer.c Message-ID: <199703131245.EAA25468@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
brian 97/03/13 04:45:39 Modified: usr.sbin/ppp Makefile chat.c main.c timer.c Added: usr.sbin/ppp sig.c sig.h Log: Reviewed by: ache@freebsd.org These changes should fix the signal "problems" in ppp. The signal changes should really be put into 2.2 too ! The following patches should do it. There were some other changes made by Andrey recently that havn't been brought into 2.2, it may be worth doing them now. diff -r -c ppp/chat.c ppp.new/chat.c *** ppp/chat.c Sat Feb 22 17:59:06 1997 --- ppp.new/chat.c Thu Mar 13 12:37:50 1997 *************** *** 34,43 **** #include <sys/time.h> #include <fcntl.h> #include <errno.h> ! #include "sig.h" #include <sys/wait.h> #include "timeout.h" #include "vars.h" #define IBSIZE 200 --- 34,44 ---- #include <sys/time.h> #include <fcntl.h> #include <errno.h> ! #include <signal.h> #include <sys/wait.h> #include "timeout.h" #include "vars.h" + #include "sig.h" #define IBSIZE 200 *************** *** 402,411 **** pipe(fids); pid = fork(); if (pid == 0) { ! pending_signal(SIGINT, SIG_DFL); ! pending_signal(SIGQUIT, SIG_DFL); ! pending_signal(SIGTERM, SIG_DFL); ! pending_signal(SIGHUP, SIG_DFL); close(fids[0]); dup2(fids[1], 1); close(fids[1]); --- 403,414 ---- pipe(fids); pid = fork(); if (pid == 0) { ! TermTimerService(); ! signal(SIGINT, SIG_DFL); ! signal(SIGQUIT, SIG_DFL); ! signal(SIGTERM, SIG_DFL); ! signal(SIGHUP, SIG_DFL); ! signal(SIGALRM, SIG_DFL); close(fids[0]); dup2(fids[1], 1); close(fids[1]); diff -r -c ppp/main.c ppp.new/main.c *** ppp/main.c Sat Feb 22 17:59:08 1997 --- ppp.new/main.c Thu Mar 13 12:37:16 1997 *************** *** 28,34 **** #include <paths.h> #include <sys/time.h> #include <termios.h> ! #include "sig.h" #include <sys/wait.h> #include <errno.h> #include <netdb.h> --- 28,34 ---- #include <paths.h> #include <sys/time.h> #include <termios.h> ! #include <signal.h> #include <sys/wait.h> #include <errno.h> #include <netdb.h> *************** *** 49,54 **** --- 49,55 ---- #include "systems.h" #include "ip.h" #include "alias.h" + #include "sig.h" #define LAUTH_M1 "Warning: No password entry for this host in ppp.secret\n" #define LAUTH_M2 "Warning: All manipulation is allowed by anyone in the world\n" *************** *** 346,360 **** tcgetattr(0, &oldtio); /* Save original tty mode */ ! pending_signal(SIGHUP, Hangup); pending_signal(SIGTERM, CloseSession); pending_signal(SIGINT, CloseSession); pending_signal(SIGQUIT, CloseSession); #ifdef SIGSEGV ! pending_signal(SIGSEGV, Hangup); #endif #ifdef SIGPIPE ! pending_signal(SIGPIPE, Hangup); #endif #ifdef SIGALRM pending_signal(SIGALRM, SIG_IGN); --- 347,361 ---- tcgetattr(0, &oldtio); /* Save original tty mode */ ! signal(SIGHUP, Hangup); pending_signal(SIGTERM, CloseSession); pending_signal(SIGINT, CloseSession); pending_signal(SIGQUIT, CloseSession); #ifdef SIGSEGV ! signal(SIGSEGV, Hangup); #endif #ifdef SIGPIPE ! signal(SIGPIPE, Hangup); #endif #ifdef SIGALRM pending_signal(SIGALRM, SIG_IGN); diff -r -c ppp/sig.c ppp.new/sig.c *** ppp/sig.c Sat Feb 22 16:10:51 1997 --- ppp.new/sig.c Thu Mar 13 12:36:53 1997 *************** *** 32,52 **** * */ #include "sig.h" #include <sys/types.h> #include "mbuf.h" #include "log.h" ! #define __MAXSIG (32) /* Sizeof u_long: Make life convenient.... */ ! static u_long caused; /* A mask of pending signals */ ! static __sighandler_t *handler[ __MAXSIG ]; /* all start at SIG_DFL */ ! /* Record a signal in the "caused" mask */ static void signal_recorder(int sig) { ! if (sig > 0 && sig <= __MAXSIG) ! caused |= (1<<(sig-1)); } --- 32,52 ---- * */ + #include <sys/cdefs.h> #include "sig.h" #include <sys/types.h> + #include <signal.h> #include "mbuf.h" #include "log.h" ! static caused[NSIG]; /* An array of pending signals */ ! static sig_type handler[NSIG]; /* all start at SIG_DFL */ ! /* Record a signal in the "caused" array */ static void signal_recorder(int sig) { ! caused[sig-1]++; } *************** *** 55,64 **** call in handle_signal() */ ! __sighandler_t *pending_signal(int sig,__sighandler_t *fn) { ! __sighandler_t *Result; ! if (sig <= 0 || sig > __MAXSIG) { /* Oops - we must be a bit out of date (too many sigs ?) */ logprintf("Eeek! %s:%s: I must be out of date!\n",__FILE__,__LINE__); return signal(sig,fn); --- 55,64 ---- call in handle_signal() */ ! sig_type pending_signal(int sig,sig_type fn) { ! sig_type Result; ! if (sig <= 0 || sig > NSIG) { /* Oops - we must be a bit out of date (too many sigs ?) */ logprintf("Eeek! %s:%s: I must be out of date!\n",__FILE__,__LINE__); return signal(sig,fn); *************** *** 66,78 **** Result = handler[sig-1]; if (fn == SIG_DFL || fn == SIG_IGN) { - handler[sig-1] = (__sighandler_t *)0; signal(sig,fn); } else { handler[sig-1] = fn; signal(sig,signal_recorder); } ! caused &= ~(1<<(sig-1)); return Result; } --- 66,78 ---- Result = handler[sig-1]; if (fn == SIG_DFL || fn == SIG_IGN) { signal(sig,fn); + handler[sig-1] = (sig_type)0; } else { handler[sig-1] = fn; signal(sig,signal_recorder); } ! caused[sig-1] = 0; return Result; } *************** *** 81,89 **** void handle_signals() { int sig; ! if (caused) ! for (sig=0; sig<__MAXSIG; sig++, caused>>=1) ! if (caused&1) (*handler[sig])(sig+1); } --- 81,95 ---- void handle_signals() { int sig; + int got; ! do { ! got = 0; ! for (sig = 0; sig < NSIG; sig++) ! if (caused[sig]) { ! caused[sig]--; ! got++; (*handler[sig])(sig+1); + } + } while(got); } diff -r -c ppp/sig.h ppp.new/sig.h *** ppp/sig.h Sun Feb 23 19:30:15 1997 --- ppp.new/sig.h Thu Mar 13 12:36:29 1997 *************** *** 32,41 **** * */ ! #include <signal.h> /* Call this instead of signal() */ ! extern __sighandler_t *pending_signal __P((int, __sighandler_t *)); /* Call this when you want things to *actually* happen */ extern void handle_signals __P((void)); --- 32,41 ---- * */ ! typedef void (*sig_type)(int); /* Call this instead of signal() */ ! extern sig_type pending_signal __P((int, sig_type)); /* Call this when you want things to *actually* happen */ extern void handle_signals __P((void)); diff -r -c ppp/timer.c ppp.new/timer.c *** ppp/timer.c Sat Feb 22 17:59:11 1997 --- ppp.new/timer.c Thu Mar 13 12:30:08 1997 *************** *** 25,34 **** #include <sys/time.h> #include <signal.h> #include "timeout.h" - #include "sig.h" #ifdef SIGALRM #include <errno.h> #endif void StopTimerNoBlock( struct pppTimer *); void ShowTimers(void); --- 25,34 ---- #include <sys/time.h> #include <signal.h> #include "timeout.h" #ifdef SIGALRM #include <errno.h> #endif + #include "sig.h" void StopTimerNoBlock( struct pppTimer *); void ShowTimers(void); Revision Changes Path 1.16 +2 -2 src/usr.sbin/ppp/Makefile 1.22 +4 -1 src/usr.sbin/ppp/chat.c 1.38 +17 -13 src/usr.sbin/ppp/main.c 1.14 +5 -8 src/usr.sbin/ppp/timer.c
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199703131245.EAA25468>