Re: [PATCH 5.6.0] local $SIG{FOO} restoration

2000-03-30 Thread Doug MacEachern

On Wed, 29 Mar 2000, Hugo wrote:
 
 I believe that this (or take2) might cause a problem for code like:
 
   sub handler { print "sig handled" }
   my $handlesub = "handler";
 
   [... something reads $handlesub in numeric context ...]
 
   $SIG{ALRM} = $handlesub;

i suppose the handler should not be restored if it was Perl's, something
along the lines of (on top of take2 patch):

--- mg.c~   Tue Mar 28 23:44:09 2000
+++ mg.cThu Mar 30 11:50:05 2000
@@ -966,7 +966,7 @@
/* cache state so we don't fetch it again */
if(sigstate == SIG_IGN)
sv_setpv(sv,"IGNORE");
-   else if (sigstate)
+   else if (sigstate  sigstate != PL_sighandlerp)
sv_setiv(sv,(IV)sigstate);
else
sv_setsv(sv,PL_sv_undef);





Re: [PATCH 5.6.0] local $SIG{FOO} restoration

2000-03-30 Thread Tom Christiansen

i suppose the handler should not be restored if it was Perl's, something
along the lines of (on top of take2 patch):

Exactly! this kind of thing is common in programs that do sigmasks
or tty mode masks.  The typical mistake is

set noecho
do something
unset noecho

or

block sigfoo
do something
unblock sigfoo

In both cases the bug is the same: you shouldn't undo something that
was already undone to start with. 

--tom



Re: [PATCH 5.6.0] local $SIG{FOO} restoration

2000-03-29 Thread Hugo

In [EMAIL PROTECTED],
Doug MacEachern writes:
:when 'local $SIG{ALRM} = sub {...}' goes out of scope, magic_setsig() sets
:the SIGALRM handler to SIG_DFL, rather than the original handler.  this
:causes quite a bit of trouble running inside of apache, since 'local
:$SIG{ALRM}' unhooks the apache SIGALRM handler for the life of that
:proccess.
:the original handler is already fetched by magic_getsig(), this patch
:saves that pointer so it can be restored in magic_setsig().
[snip]

I believe that this (or take2) might cause a problem for code like:

  sub handler { print "sig handled" }
  my $handlesub = "handler";

  [... something reads $handlesub in numeric context ...]

  $SIG{ALRM} = $handlesub;

I'm not sure how big a concern that should be, if it is true.

Hugo



[PATCH 5.6.0] local $SIG{FOO} restoration

2000-03-28 Thread Doug MacEachern

when 'local $SIG{ALRM} = sub {...}' goes out of scope, magic_setsig() sets
the SIGALRM handler to SIG_DFL, rather than the original handler.  this
causes quite a bit of trouble running inside of apache, since 'local
$SIG{ALRM}' unhooks the apache SIGALRM handler for the life of that
proccess.
the original handler is already fetched by magic_getsig(), this patch
saves that pointer so it can be restored in magic_setsig().

--- mg.c~   Sat Mar 18 19:41:03 2000
+++ mg.cTue Mar 28 22:37:07 2000
@@ -967,7 +967,7 @@
if(sigstate == SIG_IGN)
sv_setpv(sv,"IGNORE");
else
-   sv_setsv(sv,PL_sv_undef);
+   sv_setiv(sv,(IV)sigstate);
PL_psig_ptr[i] = SvREFCNT_inc(sv);
SvTEMP_off(sv);
}
@@ -1002,6 +1002,7 @@
 I32 i;
 SV** svp;
 STRLEN len;
+Sighandler_t sigstate = 0;
 
 s = MgPV(mg,len);
 if (*s == '_') {
@@ -1038,16 +1039,21 @@
*svp = SvREFCNT_inc(sv);
return 0;
 }
-s = SvPV_force(sv,len);
+if (SvIOK(sv)) {
+   sigstate = (Sighandler_t)SvIVX(sv);
+}
+else {
+   s = SvPV_force(sv,len);
+}
 if (strEQ(s,"IGNORE")) {
if (i)
(void)rsignal(i, SIG_IGN);
else
*svp = 0;
 }
-else if (strEQ(s,"DEFAULT") || !*s) {
+else if (strEQ(s,"DEFAULT") || !*s || sigstate) {
if (i)
-   (void)rsignal(i, SIG_DFL);
+   (void)rsignal(i, sigstate ? sigstate : SIG_DFL);
else
*svp = 0;
 }