add signal handler fixes from

http://www.mail-archive.com/list@epicsol.org/msg00593.html

tested by Nick@
This commit is contained in:
sthen 2009-05-01 02:04:15 +00:00
parent 8b51ee159a
commit 81f71dd16c
3 changed files with 169 additions and 4 deletions

View File

@ -1,11 +1,11 @@
# $OpenBSD: Makefile,v 1.66 2009/04/14 09:37:49 sthen Exp $
# $OpenBSD: Makefile,v 1.67 2009/05/01 02:04:15 sthen Exp $
COMMENT= (E)nhanced (P)rogrammable (I)RC-II (C)lient
VERSION= 2.10
HELP_DATE= 20050315
DISTNAME= epic4-${VERSION}
PKGNAME= ${DISTNAME}p1
PKGNAME= ${DISTNAME}p2
CATEGORIES= net
MASTER_SITES= ftp://ftp.epicsol.org/pub/epic/EPIC4-PRODUCTION/
DISTFILES= epic4-${VERSION}.tar.bz2 epic4-help-${HELP_DATE}.tar.gz
@ -28,8 +28,6 @@ SEPARATE_BUILD= simple
CONFIGURE_STYLE= gnu
# conflict between Perl embed headers and uvm_map's {max,min}_offset defines.
CONFIGURE_ENV= ac_cv_header_sys_sysctl_h=no
# using a lower optimisation level prevents random hangs (gcc 3.3.5, 2009/04)
CFLAGS+= -O0
CONFIGURE_ARGS= --without-tcl \
--enable-perl

View File

@ -0,0 +1,25 @@
$OpenBSD: patch-source_irc_c,v 1.1 2009/05/01 02:04:15 sthen Exp $
signal handler fixes
http://www.mail-archive.com/list@epicsol.org/msg00593.html
--- source/irc.c.orig Sat Mar 29 04:49:23 2008
+++ source/irc.c Tue Apr 14 21:12:58 2009
@@ -52,7 +52,7 @@ const char internal_version[] = "20080329";
/*
* In theory, this number is incremented for every commit.
*/
-const unsigned long commit_id = 769;
+const unsigned long commit_id = 770;
/*
* As a way to poke fun at the current rage of naming releases after
@@ -1155,7 +1155,7 @@ int main (int argc, char *argv[])
/* make sure we don't start with spurious signals events firing */
memset(&signals_caught, 0, NSIG * sizeof(int));
/* hook all signals! */
- hook_all_signals();
+ init_signals();
/* we *might* want to check for SIG_ERR from the above function.
* i leave it to hop to decide what to do on SIG_ERR. -pegasus
*/

View File

@ -0,0 +1,142 @@
$OpenBSD: patch-source_ircsig_c,v 1.1 2009/05/01 02:04:15 sthen Exp $
signal handler fixes
http://www.mail-archive.com/list@epicsol.org/msg00593.html
--- source/ircsig.c.orig Fri Mar 14 00:12:53 2008
+++ source/ircsig.c Tue Apr 14 21:12:59 2009
@@ -57,12 +57,13 @@ int unblock_signal (int sig_no)
}
/* array of signal handlers containing mostly NULL */
-volatile sigfunc *signal_handlers[NSIG];
+sigfunc *signal_handlers[NSIG];
+volatile int signals_caught[NSIG];
-/* grand unified signal handler, which sets flags for scriptable signals
- * -pegasus
+/* grand unified signal handler, which sets flags for scriptable signals
+ * - pegasus
*/
-RETSIGTYPE signal_handler (int sig_no)
+static RETSIGTYPE signal_handler (int sig_no)
{
signals_caught[0] = 1;
signals_caught[sig_no]++;
@@ -70,63 +71,74 @@ RETSIGTYPE signal_handler (int sig_no)
signal_handlers[sig_no](sig_no);
}
-/* hook_all_signals needs to be called in main() before my_signal()
- * if any signal hooks fail, it returns SIG_ERR, otherwise it returns
- * NULL. -pegasus
- */
-sigfunc *hook_all_signals (void)
+sigfunc *reset_one_signal (int sig_no, sigfunc *sig_handler)
{
- struct sigaction sa, osa;
- int sig_no;
- sigfunc *error = NULL;
+ struct sigaction sa, osa;
- /* docs say this is const. if it changes, something else is
- * broken. -pegasus
- */
- sa.sa_handler = &signal_handler;
- /* end possibly risky code */
- for (sig_no = 0; sig_no < NSIG; sig_no++)
- {
- signal_handlers[sig_no] = NULL;
- /* this is ugly, but the `correct' way. i hate c. -mrg */
- /* moved from my_signal. -pegasus */
- sa.sa_flags = 0;
+ if (sig_no < 0)
+ return NULL; /* Signal not implemented */
+
+ signal_handlers[sig_no] = NULL;
+
+ sa.sa_handler = sig_handler;
+ sigemptyset(&sa.sa_mask);
+ sigaddset(&sa.sa_mask, sig_no);
+
+ /* this is ugly, but the `correct' way. i hate c. -mrg */
+ sa.sa_flags = 0;
#if defined(SA_RESTART) || defined(SA_INTERRUPT)
- if (SIGALRM == sig_no || SIGINT == sig_no)
- {
+ if (SIGALRM == sig_no || SIGINT == sig_no)
+ {
# if defined(SA_INTERRUPT)
- sa.sa_flags |= SA_INTERRUPT;
+ sa.sa_flags |= SA_INTERRUPT;
# endif /* SA_INTERRUPT */
- }
- else
- {
+ }
+ else
+ {
# if defined(SA_RESTART)
- sa.sa_flags |= SA_RESTART;
+ sa.sa_flags |= SA_RESTART;
# endif /* SA_RESTART */
- }
+ }
#endif /* SA_RESTART || SA_INTERRUPT */
- /* if it wasn't for the above code, we could move the
- * sigemptyset() and sigaction() calls outside the loop
- * proper. -pegasus
- */
- sigemptyset(&sa.sa_mask);
- sigaddset(&sa.sa_mask, sig_no);
- if (0 > sigaction(sig_no, &sa, &osa))
+
+ if (0 > sigaction(sig_no, &sa, &osa))
+ return SIG_ERR;
+
+ return osa.sa_handler;
+}
+
+
+/* hook_all_signals needs to be called in main() before my_signal()
+ * if any signal hooks fail, it returns SIG_ERR, otherwise it returns
+ * NULL. - pegasus
+ */
+sigfunc * init_signals (void)
+{
+ int sig_no;
+ sigfunc *error = NULL;
+
+ memset(&signals_caught, 0, NSIG * sizeof(int));
+
+ for (sig_no = 0; sig_no < NSIG; sig_no++)
+ {
+ if ((reset_one_signal(sig_no, signal_handler)) == SIG_ERR)
error = SIG_ERR;
}
return error;
}
-sigfunc *my_signal (int sig_no, sigfunc *sig_handler)
+sigfunc * my_signal (int sig_no, sigfunc *sig_handler)
{
- sigfunc *old;
+ sigfunc *old;
- if (sig_no < 0)
- return NULL; /* Signal not implemented */
-
- /* Well this is certainly simpler. -pegasus */
old = signal_handlers[sig_no];
- signal_handlers[sig_no] = (volatile sigfunc *)sig_handler;
+ if (sig_handler == SIG_IGN || sig_handler == SIG_DFL)
+ reset_one_signal(sig_no, sig_handler);
+ else
+ {
+ reset_one_signal(sig_no, signal_handler);
+ signal_handlers[sig_no] = (sigfunc *)sig_handler;
+ }
- return old;
+ return old;
}