This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
(perl #132849) try to disable core files when deliberatly segfaulting
authorTony Cook <tony@develop-help.com>
Sun, 11 Feb 2018 23:50:24 +0000 (10:50 +1100)
committerTony Cook <tony@develop-help.com>
Mon, 12 Feb 2018 00:47:03 +0000 (11:47 +1100)
The dist/Storable/stacksize tool probes for recursion limits for
Storable, in an attempt to prevent stack overflows, and causes
segfaults when the probes exceed the available stack size.

This was leaving a core file for each failure (whether that ended
up as a single file or one for each segfault depended on the
system settings).

Try to probe for the ulimit -c option and if it doesn't cause an
error, prefix the command used to probe for recursion limits.

Ideally I could use setrlimit() for this, but we don't expose it in
core, nor in POSIX.pm, and adding it wouldn't help for the older
perls that Storable needs to build for.

dist/Storable/stacksize

index 3665d64..394e6aa 100644 (file)
@@ -30,6 +30,7 @@ sub is_miniperl {
 if (is_miniperl()) {
     die "Should not run during miniperl\n";
 }
+my $prefix = "";
 if ($^O eq "MSWin32") {
     # prevent Windows popping up a dialog each time we overflow
     # the stack
@@ -37,6 +38,11 @@ if ($^O eq "MSWin32") {
     Win32API::File->import(qw(SetErrorMode SEM_NOGPFAULTERRORBOX SEM_FAILCRITICALERRORS));
     SetErrorMode(SEM_NOGPFAULTERRORBOX() | SEM_FAILCRITICALERRORS());
 }
+# the ; here is to ensure system() passes this to the shell
+elsif (system("ulimit -c 0 ;") == 0) {
+    # try to prevent core dumps
+    $prefix = "ulimit -c 0 ; ";
+}
 if (@ARGV and $ARGV[0] eq '--core') {
     $ENV{PERL_CORE} = 1;
 }
@@ -91,7 +97,7 @@ sub cmd {
     my $code = "my \$t; \$Storable::$limit_name = -1; $try for 1..$i;dclone(\$t);";
     my $q = ($^O eq 'MSWin32') ? '"' : "'";
 
-    "$PERL $mblib -MStorable=dclone -e$q$code$q"
+    "$prefix $PERL $mblib -MStorable=dclone -e$q$code$q"
 }
 # try more
 sub good {