develooper Front page | perl.perl5.porters | Postings from November 2003

[perl #24537] HP-UX 11.00 -- SA_RESTART not allowing EINTR through to select

From:
Chaim Frenkel
Date:
November 21, 2003 21:04
Subject:
[perl #24537] HP-UX 11.00 -- SA_RESTART not allowing EINTR through to select
Message ID:
rt-24537-67722.11.2513118799287@rt.perl.org
# New Ticket Created by  Chaim Frenkel 
# Please include the string:  [perl #24537]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=24537 >


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;
---
Flags:
    category=core
    severity=high
---
Site configuration information for perl v5.8.2:

Configured by cfx at Fri Nov 14 12:34:49 EST 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 2) configuration:
  Platform:
    osname=hpux, osvers=11.00, archname=PA-RISC2.0
    uname='hp-ux nydevoc b.11.00 u 9000800 165474636 unlimited-user license '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags =' -Ae -D_HPUX_SOURCE -Wl,+vnocompatwarnings -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 ',
    optimize='+O2 +Onolimit',
    cppflags='-Aa -D__STDC_EXT__ -D_HPUX_SOURCE -Ae -D_HPUX_SOURCE -Wl,+vnocompatwarnings -I/usr/local/include'
    ccversion='B.11.11.02', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='/usr/bin/ld', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
    libs=-lnsl -lnm -lndbm -lmalloc -ldld -lm -lcrypt -lsec -lc
    perllibs=-lnsl -lnm -lmalloc -ldld -lm -lcrypt -lsec -lc
    libc=/lib/libc.sl, so=sl, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_hpux.xs, dlext=sl, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-B,deferred '
    cccdlflags='+Z', lddlflags='-b +vnocompatwarnings -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl v5.8.2:
    /u1/bea/cfx/perl5/lib/5.8.2/PA-RISC2.0
    /u1/bea/cfx/perl5/lib/5.8.2
    /u1/bea/cfx/perl5/lib/site_perl/5.8.2/PA-RISC2.0
    /u1/bea/cfx/perl5/lib/site_perl/5.8.2
    /u1/bea/cfx/perl5/lib/site_perl
    .

---
Environment for perl v5.8.2:
    HOME=/u1/bea/cfx
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/bin:/opt/ansic/bin:/usr/ccs/bin:/usr/contrib/bin:/opt/nettladm/bin:/opt/fc/bin:/opt/fcms/bin:/opt/upgrade/bin:/opt/pd/bin:/usr/bin/X11:/usr/contrib/bin/X11://opt/perl/bin:/opt/resmon/bin:/usr/sbin/diag/contrib:/opt/pred/bin:/opt/hparray/bin:/opt/perf/bin:/usr/local/bin:/opt/sudo.v1.5.7p4:/opt/hpnp//bin:/opt/ignite/bin:/opt/aCC/bin:/opt/cxperf/bin:/opt/langtools/bin:/opt/imake/bin:/sybase/ASE-12_5/bin:/sybase/OCS-12_5/bin/:/sybase/CFG-1_0/bin:/opt/OV/bin/OpC:/opt/langtools/bin:/opt/sec_mgmt/spc/bin:/opt/emc/WideSky/V5.1.0/bin:/opt/gnome/bin:.
    PERL_BADLANG (unset)
    SHELL=/usr/bin/ksh




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About