Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signal handlers and waitpid #4485

Closed
p5pRT opened this issue Oct 8, 2001 · 5 comments
Closed

signal handlers and waitpid #4485

p5pRT opened this issue Oct 8, 2001 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 8, 2001

Migrated from rt.perl.org#7799 (status was 'resolved')

Searchable as RT7799$

@p5pRT
Copy link
Author

p5pRT commented Oct 8, 2001

From [email protected]

I've written a small test-script (see below) that dumps core
because of a segmentation violation on many systems when the signal
handler is called while there is memory is allocated in the main
program. The signal handler doesn't use or modify any variable,
it's only​:

  $SIG{'CHLD'} = sub {
  while (waitpid(-1,&WNOHANG) > 0) { }
  };

I've tested this with perl-5.6.0 on AIX-4.2.1 and AIX-4.3.3 and
with perl-5.005_03 on linux-2.2.19.

The test-script and the stack backtrace is attached below...
(The random- and delay-parameters are optimised for a crash on
slower machines.)

---------- snipp! ----------
#!/usr/local/bin/perl

use strict;
use POSIX "​:sys_wait_h";

my $RAND1= 2000;
my $RAND2= 2000;
my $DELAY_MAIN = 0.1;
my $DELAY_CHILD = 2;

$SIG{'CHLD'} = sub {
  while (waitpid(-1,&WNOHANG) > 0) { }
};

my $CHILD_PID = 0;

srand();
$|= 1;

my $i;
for ($i = 1; $i < 200; $i++) {
  print "fork $i\n";
  # allocate some memory
  my ($i, $r1, $r2, @​buf);
  $r1= rand($RAND1);
  for ($i= 1; $i <= $r1; $i++) {
  $r2= rand($RAND2);
  $buf[$i] = "x" x $r2;
  }

  my $pid;
  if ($pid = fork) {
  # parent
  select(undef, undef, undef, $DELAY_MAIN);
  print " Child $pid ready\n";
  next;
  } elsif (defined $pid) {
  # child
  $SIG{'CHLD'} = 'DEFAULT';
  print " Child $$ ready\n";
  select (undef, undef, undef, rand($DELAY_CHILD));
  print " Child $$ exit\n";
  exit(0);
  }
  else {
  print "Fork error​: $!\n";
  return;
  }
}

print "Done\n";

---------- snipp! ----------

perl-5.6.0 on Linux-2.2.19​:
---------------------------
#0 chunk_alloc (ar_ptr=0x40141d40, nb=16) at malloc.c​:2814
#1 0x400ac5ae in malloc () at malloc.c​:2181
#2 0x807bbe5 in Perl_safemalloc ()
#3 0x808abb6 in Perl_sv_grow ()
#4 0x808cb10 in Perl_sv_setsv ()
#5 0x808ebf5 in Perl_sv_mortalcopy ()
#6 0x8087d8a in Perl_pp_leave ()
#7 0x80b49ad in Perl_runops_standard ()
#8 0x8059a01 in perl_call_sv ()
#9 0x8081cb8 in Perl_sighandler ()
#10 0x40071c48 in __restore () at
../sysdeps/unix/sysv/linux/i386/sigaction.c​:127
#11 0x400ac5ae in malloc () at malloc.c​:2181
#12 0x807bbe5 in Perl_safemalloc ()
#13 0x808abb6 in Perl_sv_grow ()
#14 0x808cb10 in Perl_sv_setsv ()
#15 0x808533b in Perl_pp_sassign ()
#16 0x80b49ad in Perl_runops_standard ()
#17 0x8059338 in perl_run ()
#18 0x80577e1 in main ()
#19 0x4006b9cb in __libc_start_main () at
../sysdeps/generic/libc-start.c​:122

perl-5.6.0 on AIX-4.2.1​:
------------------------
malloc_y.malloc_y(??) at 0xd02656c8
malloc.malloc(??) at 0xd0262f10
Perl_safesysmalloc() at 0x100313e4
Perl_sv_grow() at 0x10027550
Perl_sv_setsv() at 0x10024e08
Perl_pp_sassign() at 0x1007d1b8
Perl_runops_standard() at 0x1006340c
S_run_body() at 0x100007c4
perl_run() at 0x100068d0
main() at 0x100003cc

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl v5.6.0:

Configured by bergolth at Fri Oct 20 19:23:46 MES 2000.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
  Platform:
    osname=aix, osvers=4.2.1.0, archname=aix42
    uname='aix ollie 2 4 0045781a4c00 '
    config_args='-d'
    hint=previous, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define 
    use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='/usr/vac/bin/cc_r', optimize='-O', gccversion=
    cppflags='-D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -qmaxmem=16384 -I/usr/local/include -I/usr/local/BerkeleyDB.3.1/include'
    ccflags ='-D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -qmaxmem=16384 -I/usr/local/include -I/usr/local/BerkeleyDB.3.1/include'
    stdchar='unsigned char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='ld', ldflags ='-L/usr/local/lib -L/usr/local/BerkeleyDB.3.1/lib'
    libpth=/usr/local/lib /usr/local/BerkeleyDB.3.1/lib /lib /usr/lib /usr/ccs/lib
    libs=-lbind -lnsl -ldbm -ldl -lld -lm -lC -lc -lbsd -lPW -liconv -ldb
    libc=, so=a, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_aix.xs, dlext=so, d_dlsymun=undef, ccdlflags='  -bE:/usr/local/lib/perl5/5.6.0/aix42/CORE/perl.exp -bE:/usr/local/lib/perl5/5.6.0/aix42/CORE/perl.exp -bE:/usr/local/lib/perl5/5.6.0/aix42/CORE/perl.exp -bE:/usr/local/lib/perl5/5.6.0/aix42/CORE
/perl.exp -bE:/usr/local/lib/perl5/5.6.0/aix42/CORE/perl.exp'
    cccdlflags=' ', lddlflags='-bhalt:4 -bM:SRE -bI:$(PERL_INC)/perl.exp -bE:$(BASEEXT).exp -b noentry -lC -lc -L/usr/local/lib -L/usr/local/BerkeleyDB.3.1/lib'

Locally applied patches:
    


@INC for perl v5.6.0:
    /usr/local/lib/perl5/5.6.0/aix42
    /usr/local/lib/perl5/5.6.0
    /usr/local/lib/perl5/site_perl/5.6.0/aix42
    /usr/local/lib/perl5/site_perl/5.6.0
    /usr/local/lib/perl5/site_perl
    .


Environment for perl v5.6.0:
    HOME=/afs/wu-wien.ac.at/home/edvz/bergolth
    LANG=C
    LANGUAGE (unset)
    LC_ALL=C
    LC_CTYPE=C
    LC__FASTMSG=true
    LD_LIBRARY_PATH (unset)
    LIBPATH (unset)
    LOGDIR (unset)
    PATH=/afs/wu-wien.ac.at/home/edvz/bergolth/bin:/afs/wu-wien.ac.at/home/edvz/bergolth/work/bin:/usr/ucb:/bin:/usr/bin:/usr/bin/X11:/usr/sbin:/usr/local/bin:/usr/afsws/local/bin:/usr/afsws/bin:/afs/wu/common/infoserv/hotline:/db/app/oracle/product/7.3.2
/bin/:/afs/wu/home/edvz/bergolth/notes
    PERL_BADLANG (unset)
    SHELL=/usr/bin/tcsh

@p5pRT
Copy link
Author

p5pRT commented Nov 27, 2002

From @jhi

Hi, if you could retry your code under Perl 5.8.0? In Perl 5.8.0 signals are 'safe' meaning that signals should not be able to corrupt Perl's internal state as you observed.

@p5pRT
Copy link
Author

p5pRT commented Nov 30, 2002

From [email protected]

Jarkko Hietaniemi (via RT) wrote​:

Hi, if you could retry your code under Perl 5.8.0? In Perl 5.8.0
signals are 'safe' meaning that signals should not be able to corrupt
Perl's internal state as you observed.

Great!
I'll retry the code as soon as I've upgraded my perl-version.

Thanks,
--leo


Alexander (Leo) Bergolth leo@​leo.wu-wien.ac.at
WU-Wien - Zentrum fuer Informatikdienste http​://leo.wu-wien.ac.at
  Computers are like air conditioners -
  they stop working properly when you open Windows

@p5pRT
Copy link
Author

p5pRT commented Feb 2, 2003

From [email protected]

This is believed fixed by "safe signals" in perl5.8.0 and later.

@p5pRT
Copy link
Author

p5pRT commented Feb 2, 2003

[email protected] - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant