Front page | perl.perl5.porters |
Postings from May 2012
[perl #24537] HP-UX 11.00 -- SA_RESTART not allowing EINTR through to select
Thread Next
From:
James E Keenan via RT
Date:
May 24, 2012 18:17
Subject:
[perl #24537] HP-UX 11.00 -- SA_RESTART not allowing EINTR through to select
Message ID:
rt-3.6.HEAD-7788-1337908623-1922.24537-15-0@perl.org
On Fri Nov 21 07:42:11 2003, chaimf@pobox.com wrote:
> This is a bug report for perl from chaimf@pobox.com
> generated with the help of perlbug 1.34 running under perl v5.8.2.
>
> The select call does not notice every SIGCHILD.
>
> Even with a sigaction turning off SA_RESTART on SIGCHLD it only reacts
> after
> all the children are done.
>
> I need to be able to notice each SIGCHLD while waiting in a select
> call.
>
> I have been unable to reproduce the action in c code. In the c code,
> if
> SA_RESTART is off, each SIGCHLD causes the select to return with
> EINTR.
>
> ---[output]---
> [29785]: doit: current handler is: main::c
> [29785]: started pid=29786
> [29786]: Sleeping for a while
> [29787]: Sleeping for a while
> [29785]: started pid=29787
> [29785]: Waiting in select
> [29787]: Awoken. Will leave nastily
> Illegal division by zero at ./child.pl line 46.
> [29785]: sa_handler invoked <CHLD>
> [29785]: reaping child.
> [29785]: pid 29787 - ret(255) signal(0) dumped(0)
> <<
> << I expect a Select returned -1 here
> <<
> [29786]: Awoken. Will leave nicely
> [29785]: pid 29786 - ret(0) signal(0) dumped(0)
> [29785]: sa_handler invoked <CHLD>
> [29785]: reaping child.
> [29785]: Select returned -1 left=10
> [29785]: Waiting in select
> [29785]: Select returned 0 left=10
> [29785]: Waiting in select
> [29785]: Select returned 0 left=10
> [29785]: Waiting in select
> [29785]: Select returned 0 left=10
>
>
> ---[Code]---
> #!/u1/bea/cfx/perl5/bin/perl -w
>
> $| = 1;
>
>
> use POSIX qw(:signal_h :fcntl_h :sys_stat_h :sys_wait_h :time_h);
> sub c()
> {
> print "[$$]: sa_handler invoked <", join(",", @_), ">\n";
> print "[$$]: reaping child.\n";
> while (-1 != ($somePid = waitpid(-1, 0) )) {
> $status = $?;
> print "[$$]: pid $somePid - ret(", $status >>8
> , ") signal(", $status & 127
> ,") dumped(", $status & 128
> ,")\n";
> }
> }
>
> sub turnoff_sarestart
> {
> my $sigact = POSIX::SigAction->new('DEFAULT');
> my $newsig = POSIX::SigAction->new('DEFAULT');
>
> sigaction(SIGCHLD, $sigact, $newsig); # get the value
> $newsig->{FLAGS} &= ~SA_RESTART; # Turn off SA_RESTART
> sigaction(SIGCHLD, $newsig, $sigact); # get the value
> }
>
> sub startem
> {
> unless ($pid = fork) {
> print "[$$]: Sleeping for a while\n";
> sleep(5);
> print "[$$]: Awoken. Will leave nicely\n";
> exit 0;
> }
>
> print "[$$]: started pid=$pid\n";
>
> unless ($pid = fork) {
> print "[$$]: Sleeping for a while\n";
> sleep(2);
> print "[$$]: Awoken. Will leave nastily\n";
> $foo = 1; $bar = 0;
> print $foo / $bar;
> exit 1;
> }
> print "[$$]: started pid=$pid\n";
> }
>
> sub doit
> {
> $SIG{CHLD} = "c";
> &turnoff_sarestart;
>
> print "[$$]: doit: current handler is: $SIG{CHLD}\n";
>
> startem;
>
> for (0..3) {
> print "[$$]: Waiting in select\n";
> $r = $w = $e = "";
> ($ret,$left) = select($r, $w, $e, 10);
> print "[$$]: Select returned $ret left=$left\n";
> }
> }
>
>
> &doit;
> exit 0;
Hugmeir reported on #p5p tonight, "I can reproduce this in HP-UX, Linux,
and OpenBSD. I don't know the first thing about signals, so could
someone check if this actually a bug?"
I know just as little about signals. I reproduced the problem on Darwin
with a version of chaimf's program (attached) cleaned up a bit to run
under 'use strict'.
Thank you very much.
Jim Keenan
---
via perlbug: queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=24537
Thread Next
-
[perl #24537] HP-UX 11.00 -- SA_RESTART not allowing EINTR through to select
by James E Keenan via RT