summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1997-03-13 12:45:35 +0000
committerbrian <brian@FreeBSD.org>1997-03-13 12:45:35 +0000
commitdb1507dc21cd44caa52ead85f9a6a42d0d986982 (patch)
treefa504756c008684108eea2200c879f5791919788
parentd595a2d0872984b79873b4152ae4550b61e185a6 (diff)
downloadFreeBSD-src-db1507dc21cd44caa52ead85f9a6a42d0d986982.zip
FreeBSD-src-db1507dc21cd44caa52ead85f9a6a42d0d986982.tar.gz
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.
-rw-r--r--usr.sbin/ppp/Makefile4
-rw-r--r--usr.sbin/ppp/chat.c5
-rw-r--r--usr.sbin/ppp/main.c30
-rw-r--r--usr.sbin/ppp/sig.c95
-rw-r--r--usr.sbin/ppp/sig.h41
-rw-r--r--usr.sbin/ppp/timer.c13
6 files changed, 164 insertions, 24 deletions
diff --git a/usr.sbin/ppp/Makefile b/usr.sbin/ppp/Makefile
index a0cf1d2..a8f6ba3 100644
--- a/usr.sbin/ppp/Makefile
+++ b/usr.sbin/ppp/Makefile
@@ -1,11 +1,11 @@
-# $Id: Makefile,v 1.14 1997/02/22 16:09:55 peter Exp $
+# $Id: Makefile,v 1.15 1997/03/09 20:03:27 ache Exp $
PROG= ppp
SRCS= async.c auth.c ccp.c chap.c chat.c command.c filter.c fsm.c hdlc.c \
ip.c ipcp.c lcp.c lqr.c log.c main.c mbuf.c modem.c os.c \
pap.c pred.c route.c slcompress.c timer.c systems.c uucplock.c vars.c \
vjcomp.c arp.c alias.c alias_db.c alias_ftp.c alias_util.c \
- passwdauth.c
+ passwdauth.c sig.c
#CFLAGS+= -DHAVE_SHELL_CMD_WITH_ANY_MODE
CFLAGS += -Wall -DUSE_PERROR -DMSEXT -DPASSWDAUTH
LDADD += -lmd -lcrypt -lutil
diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c
index bab5a9a..d865801 100644
--- a/usr.sbin/ppp/chat.c
+++ b/usr.sbin/ppp/chat.c
@@ -18,7 +18,7 @@
* Columbus, OH 43221
* (614)451-1883
*
- * $Id: chat.c,v 1.20 1997/03/09 20:03:34 ache Exp $
+ * $Id: chat.c,v 1.21 1997/03/09 20:09:14 ache Exp $
*
* TODO:
* o Support more UUCP compatible control sequences.
@@ -38,6 +38,7 @@
#include <sys/wait.h>
#include "timeout.h"
#include "vars.h"
+#include "sig.h"
#define IBSIZE 200
@@ -402,10 +403,12 @@ char *command, *out;
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 --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c
index 0e39301..6e83847 100644
--- a/usr.sbin/ppp/main.c
+++ b/usr.sbin/ppp/main.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: main.c,v 1.36 1997/03/09 20:03:39 ache Exp $
+ * $Id: main.c,v 1.37 1997/03/10 06:21:01 ache Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@@ -49,6 +49,7 @@
#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"
@@ -213,8 +214,8 @@ int signo;
static void
TerminalCont()
{
- (void)signal(SIGCONT, SIG_DFL);
- (void)signal(SIGTSTP, TerminalStop);
+ pending_signal(SIGCONT, SIG_DFL);
+ pending_signal(SIGTSTP, TerminalStop);
TtyCommandMode(getpgrp() == tcgetpgrp(0));
}
@@ -222,9 +223,9 @@ static void
TerminalStop(signo)
int signo;
{
- (void)signal(SIGCONT, TerminalCont);
+ pending_signal(SIGCONT, TerminalCont);
TtyOldMode();
- signal(SIGTSTP, SIG_DFL);
+ pending_signal(SIGTSTP, SIG_DFL);
kill(getpid(), signo);
}
@@ -349,9 +350,9 @@ char **argv;
tcgetattr(0, &oldtio); /* Save original tty mode */
signal(SIGHUP, Hangup);
- signal(SIGTERM, CloseSession);
- signal(SIGINT, CloseSession);
- signal(SIGQUIT, CloseSession);
+ pending_signal(SIGTERM, CloseSession);
+ pending_signal(SIGINT, CloseSession);
+ pending_signal(SIGQUIT, CloseSession);
#ifdef SIGSEGV
signal(SIGSEGV, Hangup);
#endif
@@ -359,18 +360,18 @@ char **argv;
signal(SIGPIPE, Hangup);
#endif
#ifdef SIGALRM
- signal(SIGALRM, SIG_IGN);
+ pending_signal(SIGALRM, SIG_IGN);
#endif
if(mode & MODE_INTER)
{
#ifdef SIGTSTP
- signal(SIGTSTP, TerminalStop);
+ pending_signal(SIGTSTP, TerminalStop);
#endif
#ifdef SIGTTIN
- signal(SIGTTIN, TerminalStop);
+ pending_signal(SIGTTIN, TerminalStop);
#endif
#ifdef SIGTTOU
- signal(SIGTTOU, SIG_IGN);
+ pending_signal(SIGTTOU, SIG_IGN);
#endif
}
@@ -796,6 +797,8 @@ DoLoop()
#ifndef SIGALRM
usleep(TICKUNIT);
TimerService();
+#else
+ handle_signals();
#endif
/* If there are aren't many packets queued, look for some more. */
@@ -836,7 +839,8 @@ DoLoop()
if ( i < 0 ) {
if ( errno == EINTR ) {
- continue; /* Got a signal - should have been dealt with */
+ handle_signals();
+ continue;
}
perror("select");
break;
diff --git a/usr.sbin/ppp/sig.c b/usr.sbin/ppp/sig.c
new file mode 100644
index 0000000..c54ea77
--- /dev/null
+++ b/usr.sbin/ppp/sig.c
@@ -0,0 +1,95 @@
+/*-
+ * Copyright (c) 1997
+ * Brian Somers <brian@awfulhak.demon.co.uk>. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: sig.c,v 1.4 1997/02/25 14:05:10 brian Exp $
+ *
+ * TODO:
+ *
+ */
+
+#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]++;
+}
+
+
+/*
+ set up signal_recorder, and record handler as the function to ultimately
+ 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);
+ }
+
+ 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;
+}
+
+
+/* Call the handlers for any pending signals */
+
+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 --git a/usr.sbin/ppp/sig.h b/usr.sbin/ppp/sig.h
new file mode 100644
index 0000000..42598a6
--- /dev/null
+++ b/usr.sbin/ppp/sig.h
@@ -0,0 +1,41 @@
+/*-
+ * Copyright (c) 1997
+ * Brian Somers <brian@awfulhak.demon.co.uk>. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: sig.h,v 1.5 1997/02/25 14:05:13 brian Exp $
+ *
+ * TODO:
+ *
+ */
+
+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 --git a/usr.sbin/ppp/timer.c b/usr.sbin/ppp/timer.c
index 629da58..8460992 100644
--- a/usr.sbin/ppp/timer.c
+++ b/usr.sbin/ppp/timer.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: timer.c,v 1.12 1997/03/09 20:03:51 ache Exp $
+ * $Id: timer.c,v 1.13 1997/03/09 20:09:17 ache Exp $
*
* TODO:
*/
@@ -28,6 +28,8 @@
#ifdef SIGALRM
#include <errno.h>
#endif
+#include "sig.h"
+
void StopTimerNoBlock( struct pppTimer *);
void ShowTimers(void);
@@ -269,7 +271,7 @@ void usleep( u_int usec)
void InitTimerService( void ) {
struct itimerval itimer;
- signal(SIGALRM, (void (*)(int))TimerService);
+ pending_signal(SIGALRM, (void (*)(int))TimerService);
itimer.it_interval.tv_sec = itimer.it_value.tv_sec = 0;
itimer.it_interval.tv_usec = itimer.it_value.tv_usec = TICKUNIT;
setitimer(ITIMER_REAL, &itimer, NULL);
@@ -278,13 +280,8 @@ void InitTimerService( void ) {
void TermTimerService( void ) {
struct itimerval itimer;
- itimer.it_interval.tv_sec = itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = itimer.it_value.tv_sec = 0;
setitimer(ITIMER_REAL, &itimer, NULL);
- /*
- * Notes: after disabling timer here, we will get one
- * SIGALRM will be got.
- */
- signal(SIGALRM, SIG_IGN);
+ pending_signal(SIGALRM, SIG_IGN);
}
#endif
OpenPOWER on IntegriCloud