From: Jarkko Hietaniemi Date: Tue, 16 Jul 2002 02:26:12 +0000 (+0000) Subject: Integrate change #16844 from maint: X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a10b1e109d1f901ff6cb267ca6a30834468b37b7;p=p5sagit%2Fp5-mst-13.2.git Integrate change #16844 from maint: extension of change#16332: isolate signal diddling to the main interpreter (fixes signal-related races, e.g. when multiple threads run system()) p4raw-link: @16844 on //depot/maint-5.6/perl: 9bc2ac260e3c5ad531ff50393278b22d570db209 p4raw-link: @16332 on //depot/maint-5.6/perl: 9bf7742e23b67e3d7c671615795c570c51951513 p4raw-id: //depot/perl@17569 p4raw-integrated: from //depot/maint-5.6/perl@17567 'merge in' util.c (@16508..) --- diff --git a/util.c b/util.c index e42efe3..7355b96 100644 --- a/util.c +++ b/util.c @@ -2349,6 +2349,12 @@ Perl_rsignal(pTHX_ int signo, Sighandler_t handler) { struct sigaction act, oact; +#ifdef USE_ITHREADS + /* only "parent" interpreter can diddle signals */ + if (PL_curinterp != aTHX) + return SIG_ERR; +#endif + act.sa_handler = handler; sigemptyset(&act.sa_mask); act.sa_flags = 0; @@ -2383,6 +2389,12 @@ Perl_rsignal_save(pTHX_ int signo, Sighandler_t handler, Sigsave_t *save) { struct sigaction act; +#ifdef USE_ITHREADS + /* only "parent" interpreter can diddle signals */ + if (PL_curinterp != aTHX) + return -1; +#endif + act.sa_handler = handler; sigemptyset(&act.sa_mask); act.sa_flags = 0; @@ -2401,6 +2413,12 @@ Perl_rsignal_save(pTHX_ int signo, Sighandler_t handler, Sigsave_t *save) int Perl_rsignal_restore(pTHX_ int signo, Sigsave_t *save) { +#ifdef USE_ITHREADS + /* only "parent" interpreter can diddle signals */ + if (PL_curinterp != aTHX) + return -1; +#endif + return sigaction(signo, save, (struct sigaction *)NULL); } @@ -2409,6 +2427,12 @@ Perl_rsignal_restore(pTHX_ int signo, Sigsave_t *save) Sighandler_t Perl_rsignal(pTHX_ int signo, Sighandler_t handler) { +#ifdef USE_ITHREADS + /* only "parent" interpreter can diddle signals */ + if (PL_curinterp != aTHX) + return SIG_ERR; +#endif + return PerlProc_signal(signo, handler); } @@ -2427,6 +2451,12 @@ Perl_rsignal_state(pTHX_ int signo) { Sighandler_t oldsig; +#ifdef USE_ITHREADS + /* only "parent" interpreter can diddle signals */ + if (PL_curinterp != aTHX) + return SIG_ERR; +#endif + sig_trapped = 0; oldsig = PerlProc_signal(signo, sig_trap); PerlProc_signal(signo, oldsig); @@ -2438,6 +2468,11 @@ Perl_rsignal_state(pTHX_ int signo) int Perl_rsignal_save(pTHX_ int signo, Sighandler_t handler, Sigsave_t *save) { +#ifdef USE_ITHREADS + /* only "parent" interpreter can diddle signals */ + if (PL_curinterp != aTHX) + return -1; +#endif *save = PerlProc_signal(signo, handler); return (*save == SIG_ERR) ? -1 : 0; } @@ -2445,6 +2480,11 @@ Perl_rsignal_save(pTHX_ int signo, Sighandler_t handler, Sigsave_t *save) int Perl_rsignal_restore(pTHX_ int signo, Sigsave_t *save) { +#ifdef USE_ITHREADS + /* only "parent" interpreter can diddle signals */ + if (PL_curinterp != aTHX) + return -1; +#endif return (PerlProc_signal(signo, *save) == SIG_ERR) ? -1 : 0; }