From: Perl 5 Porters Date: Thu, 4 Jan 1996 00:49:12 +0000 (+0000) Subject: perl 5.002beta1h patch: mg.c X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3d37d572263f014bc820cfc5b23dcae8df5b95f1;p=p5sagit%2Fp5-mst-13.2.git perl 5.002beta1h patch: mg.c Set up a reliable signal handler, courtesy of Kenneth Albanowski. This needs to be documented still. The idea is that even on System V systems, you won't have to reset the signal handler as the first action inside your signal handler. --- diff --git a/mg.c b/mg.c index d58b0cf..9461515 100644 --- a/mg.c +++ b/mg.c @@ -531,6 +531,49 @@ MAGIC* mg; return 0; } +#ifdef HAS_SIGACTION +/* set up reliable signal() clone */ + +typedef void (*Sigfunc) _((int)); + +static +Sigfunc rsignal(signo,handler) +int signo; +Sigfunc handler; +{ + struct sigaction act,oact; + + act.sa_handler = handler; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; +#ifdef SIGALRM + if (signo == SIGALRM) { +#else + if (0) { +#endif +#ifdef SA_INTERRUPT + act.sa_flags |= SA_INTERRUPT; /* SunOS */ +#endif + } else { +#ifdef SA_RESTART + act.sa_flags |= SA_RESTART; /* SVR4, 4.3+BSD */ +#endif + } + if (sigaction(signo, &act, &oact) < 0) + return(SIG_ERR); + else + return(oact.sa_handler); +} + +#else + +/* ah well, so much for reliability */ + +#define rsignal(x,y) signal(x,y) + +#endif + + int magic_setsig(sv,mg) SV* sv; @@ -566,7 +609,7 @@ MAGIC* mg; } if (SvTYPE(sv) == SVt_PVGV || SvROK(sv)) { if (i) - (void)signal(i,sighandler); + (void)rsignal(i,sighandler); else *svp = SvREFCNT_inc(sv); return 0; @@ -574,13 +617,13 @@ MAGIC* mg; s = SvPV_force(sv,na); if (strEQ(s,"IGNORE")) { if (i) - (void)signal(i,SIG_IGN); + (void)rsignal(i,SIG_IGN); else *svp = 0; } else if (strEQ(s,"DEFAULT") || !*s) { if (i) - (void)signal(i,SIG_DFL); + (void)rsignal(i,SIG_DFL); else *svp = 0; } @@ -590,7 +633,7 @@ MAGIC* mg; sv_setpv(sv,tokenbuf); } if (i) - (void)signal(i,sighandler); + (void)rsignal(i,sighandler); else *svp = SvREFCNT_inc(sv); }