From b6e773acc9f27118b215a892ba704123a6df7b72 Mon Sep 17 00:00:00 2001 From: Kevin Steves Date: Sun, 4 Feb 2001 13:20:36 +0000 Subject: [PATCH] - (stevesk) add mysignal() wrapper and use it for the protocol 2 SIGCHLD handler. --- ChangeLog | 2 ++ misc.c | 23 +++++++++++++++++++++++ misc.h | 4 ++++ serverloop.c | 4 ++-- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8c5391ce7..9ab110c61 100644 --- a/ChangeLog +++ b/ChangeLog @@ -29,6 +29,8 @@ - (djm) Update several bits for new optional reverse lookup stuff. I think I got them all. - (djm) Makefile.in fixes + - (stevesk) add mysignal() wrapper and use it for the protocol 2 + SIGCHLD handler. 20010103 - (bal) Cygwin clean up by Corinna Vinschen diff --git a/misc.c b/misc.c index 2d7b2fa60..a073c9052 100644 --- a/misc.c +++ b/misc.c @@ -27,6 +27,7 @@ #include "includes.h" RCSID("$OpenBSD: util.c,v 1.6 2000/10/27 07:32:19 markus Exp $"); +#include "misc.h" #include "ssh.h" #include "log.h" @@ -95,3 +96,25 @@ strdelim(char **s) return (old); } + +mysig_t +mysignal(int sig, mysig_t act) +{ +#ifdef HAVE_SIGACTION + struct sigaction sa, osa; + + if (sigaction(sig, 0, &osa) == -1) + return (mysig_t) -1; + if (osa.sa_handler != act) { + memset(&sa, 0, sizeof sa); + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sa.sa_handler = act; + if (sigaction(sig, &sa, 0) == -1) + return (mysig_t) -1; + } + return (osa.sa_handler); +#else + return (signal(sig, act)); +#endif +} diff --git a/misc.h b/misc.h index 16370425a..1dd038960 100644 --- a/misc.h +++ b/misc.h @@ -19,3 +19,7 @@ char *strdelim(char **s); /* set filedescriptor to non-blocking */ void set_nonblock(int fd); + +/* wrapper for signal interface */ +typedef void (*mysig_t)(int); +mysig_t mysignal(int sig, mysig_t act); diff --git a/serverloop.c b/serverloop.c index bdac6a0d2..353733d31 100644 --- a/serverloop.c +++ b/serverloop.c @@ -110,7 +110,7 @@ sigchld_handler2(int sig) int save_errno = errno; debug("Received SIGCHLD."); child_terminated = 1; - signal(SIGCHLD, sigchld_handler2); + mysignal(SIGCHLD, sigchld_handler2); errno = save_errno; } @@ -639,7 +639,7 @@ server_loop2(void) debug("Entering interactive session for SSH2."); - signal(SIGCHLD, sigchld_handler2); + mysignal(SIGCHLD, sigchld_handler2); signal(SIGPIPE, SIG_IGN); child_terminated = 0; connection_in = packet_get_connection_in();