From: Andrew Pimlott Date: Mon, 12 Jul 2004 21:06:01 +0000 (-0400) Subject: Re: debugger 'R'estart and open database connections X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ca28b541c9845a7610e3eca36472b9ee994eb64c;p=p5sagit%2Fp5-mst-13.2.git Re: debugger 'R'estart and open database connections Message-ID: <20040713010601.GF8232@pimlott.net> p4raw-id: //depot/perl@23089 --- diff --git a/lib/perl5db.pl b/lib/perl5db.pl index 4944e5c..7b443fe 100644 --- a/lib/perl5db.pl +++ b/lib/perl5db.pl @@ -3185,6 +3185,24 @@ Return to any given position in the B-history list $cmd =~ /^(R|rerun\s*(.*))$/ && do { my @args = ($1 eq 'R' ? restart() : rerun($2)); + # Close all non-system fds for a clean restart. A more + # correct method would be to close all fds that were not + # open when the process started, but this seems to be + # hard. See "debugger 'R'estart and open database + # connections" on p5p. + + my $max_fd; + if (eval { require POSIX }) { + $max_fd = POSIX::sysconf(POSIX::_SC_OPEN_MAX()); + } + + if (defined $max_fd) { + foreach ($^F+1 .. $max_fd-1) { + next unless open FD_TO_CLOSE, "<&=$_"; + close(FD_TO_CLOSE); + } + } + # And run Perl again. We use exec() to keep the # PID stable (and that way $ini_pids is still valid). exec(@args) || print $OUT "exec failed: $!\n";