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

[perl #24525] Linux sigaction SIGCHLD vs popen race condition

From:
perlbug-followup
Date:
November 21, 2003 21:08
Subject:
[perl #24525] Linux sigaction SIGCHLD vs popen race condition
Message ID:
rt-24525-67647.5.87890603611946@rt.perl.org
# New Ticket Created by  mengel@bldlinux73.fnal.gov 
# Please include the string:  [perl #24525]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=24525 >



This is a bug report for perl from mengel@fnal.gov,
generated with the help of perlbug 1.34 running under perl v5.8.0.


-----------------------------------------------------------------

On Linux with 2.4 kernel and 2.2.5 libc, the stock Configure and build 
gives intermittent errors (at a rate dependant on system load) if you 
have repeated
	open(X,"cmd |");
	...
	close(X);
as well as a 
	$SIG{SIGCHLD} = \&reaper;
on (at least) releases perl 5.006 through 5.8.0

This does not appear to occur with libc 2.3.2.

This behavior can be fixed by setting 

d_sigaction='undef'
d_sigprocmask='undef'

in config.sh

This is demonstrated with the following short test, which I request
gets added to io/pipe.t, or wherever else makes sense:
- - - - - - - - - - - - - cut here - - - - - - - - - - - - - - - - - 
#!/usr/bin/env perl

$^W = 1;

&popen_race_test;

sub popen_race_test() {

    my ($count, $pass, $fail) = (0, 0, 0);

    while ($count < 400) {

      ++$count;

      $SIG{CHLD} = 'DEFAULT';
      $SIG{PIPE} = 'DEFAULT';

      $res1 = test_once();

      $SIG{CHLD} = \&reaper;
      $SIG{PIPE} = 'IGNORE';

      $res2 = test_once();

      if ($res1 or $res2) {
	++$fail;
      } else {
	++$pass;
      }
    }

    if ($fail > 0) {
       print "not ok - reaper vs popen race failed $fail out of $count\n";
    } else {
       print "ok - reaper vs popen race passed all $count\n";
    }
}

sub reaper {
  my $waitedpid;
  while (($waitedpid = wait()) > 0) {
    ;
  }
}

sub test_once {
  open(DF, "echo testing |") or do {
    return 1;
  };
  my $line=<DF>;
  if (! defined $line) {
    close DF;
    return 1;
  }
  close DF;
  return 0;
}
- - - - - - - - - - - - - cut here - - - - - - - - - - - - - - - - - 

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=medium
---
Site configuration information for perl v5.8.0:

Configured by mengel at Tue Nov 18 12:19:17 CST 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.4.18-5smp, archname=i686-linux-thread-multi
    uname='linux bldlinux73.fnal.gov 2.4.18-5smp #1 smp mon jun 10 15:19:40 edt 2002 i686 unknown '
    config_args='-des'
    hint=previous, useposix=true, d_sigaction=undef
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O3',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm'
    ccversion='', gccversion='2.96 20000731 (Red Hat Linux 7.3 2.96-112)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldl -lm -lpthread -lc -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil
    libc=/lib/libc-2.2.5.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.2.5'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl v5.8.0:
    /afs/fnal.gov/ups/perl/v5_8/Linux+2.4-2.2.5/lib/site_perl/5.8.0/i686-linux-thread-multi
    /afs/fnal.gov/ups/perl/v5_8/Linux+2.4-2.2.5/lib/site_perl/5.8.0
    /afs/fnal.gov/ups/perl/v5_8/Linux+2.4-2.2.5/lib/site_perl/5.8.0/arch
    /afs/fnal.gov/ups/perl/v5_8/Linux+2.4-2.2.5/lib/5.8.0/i686-linux-thread-multi
    /afs/fnal.gov/ups/perl/v5_8/Linux+2.4-2.2.5/lib/5.8.0
    /afs/fnal.gov/ups/perl/v5_8/Linux+2.4-2.2.5/lib/5.8.0/arch
    /tmp/build-perl-v5_8/lib/5.8.0/i686-linux-thread-multi
    /tmp/build-perl-v5_8/lib/5.8.0
    /tmp/build-perl-v5_8/lib/site_perl/5.8.0/i686-linux-thread-multi
    /tmp/build-perl-v5_8/lib/site_perl/5.8.0
    /tmp/build-perl-v5_8/lib/site_perl
    .

---
Environment for perl v5.8.0:
    HOME=/afs/fnal/files/home/room1/mengel
    LANG=en_US
    LANGUAGE (unset)
    LC_COLLATE=C
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/afs/fnal.gov/ups/perl/v5_8/Linux+2.4-2.2.5/bin:.:/afs/fnal.gov/products/UNIX/frame/v5_1a/bin:/fnal/ups/prd/flpr/v1_12/Linux-2/bin:/afs/fnal/ups/xemacs/v21_1/Linux+2/bin:/afs/fnal.gov/ups/ispell/v3_1b/Linux+2/bin:/afs/fnal.gov/ups/rcs/v5_7/Linux+2/bin:/afs/fnal.gov/ups/diffutils/v2_7/Linux+2/bin:/afs/fnal.gov/ups/cvs/v1_11_5/Linux+2/bin:/afs/fnal.gov/ups/gtools/v2_4b/Linux+2_c/bin:/afs/fnal.gov/ups/rcs/v5_7/Linux+2/bin:/afs/fnal.gov/ups/diffutils/v2_7/Linux+2/bin:/afs/fnal.gov/ups/cvs/v1_11_5/Linux+2/bin:/afs/fnal.gov/ups/tex/v_tetex_1_0_5/Linux+2.2:/afs/fnal.gov/ups/xanim/v2_70_64/Linux+2/bin:/afs/fnal.gov/ups/xfig/v3_20/Linux+2/bin:/afs/fnal.gov/ups/imagemagick/v4_04/Linux+2/bin:/afs/fnal.gov/ups/ghostscript/v5_50/Linux+2/bin:/afs/fnal.gov/ups/imagelibs/v1_0/Linux+2:/afs/fnal.gov/ups/ximagetools/v4_0/NULL/bin:/afs/fnal.gov/ups/ispell/v3_1b/Linux+2/bin:/afs/fnal.gov/ups/pine/v4_58/Linux+2.4.18/bin:/local/ups/prd/ups/v4_7_1/Linux-2/bin:/usr/games:/afs/fnal/files/hom!
e/room1/mengel/bin.Linux:/afs/fnal/files/home/room1/mengel/bin:/opt/TWWfsw/bin:/usr/krb5/bin:/usr/local/bin:/usr/bin:/usr/sbin:/etc:/usr/etc:/bin:/sbin:/usr/afsws/bin:/usr/bin/X11:/usr/X11R6/bin:.
    PERL5LIB=/afs/fnal.gov/ups/perl/v5_8/Linux+2.4-2.2.5/lib/site_perl/5.8.0:/afs/fnal.gov/ups/perl/v5_8/Linux+2.4-2.2.5/lib/site_perl/5.8.0/arch:/afs/fnal.gov/ups/perl/v5_8/Linux+2.4-2.2.5/lib/5.8.0:/afs/fnal.gov/ups/perl/v5_8/Linux+2.4-2.2.5/lib/5.8.0/arch
    PERL_BADLANG (unset)
    PERL_DIR=/afs/fnal.gov/ups/perl/v5_8/Linux+2.4-2.2.5
    SHELL=/usr/local/bin/bash




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