This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
SelfLoader after fork()
authorIlya Zakharevich <ilya@math.berkeley.edu>
Mon, 18 Dec 2006 01:13:59 +0000 (17:13 -0800)
committerSteve Peters <steve@fisharerojo.org>
Thu, 21 Dec 2006 05:47:31 +0000 (05:47 +0000)
Message-ID: <20061218091359.GA14985@powdermilk.math.berkeley.edu>

p4raw-id: //depot/perl@29606

lib/SelfLoader.pm

index ad58f6e..0c2daeb 100644 (file)
@@ -60,6 +60,11 @@ sub _load_stubs {
     print STDERR "SelfLoader::load_stubs($callpack)\n" if $DEBUG;
     croak("$callpack doesn't contain an __DATA__ token")
         unless defined fileno($fh);
+    # Protect: fork() shares the file pointer between the parent and the kid
+    open my $nfh, '<&', $fh or croak "reopen: $!";# dup() the fd
+    close $fh or die "close: $1";                 # autocloses, but be paranoid
+    open $fh, '<&', $nfh or croak "reopen2: $!";  # dup() the fd "back"
+    close $nfh or die "close after reopen: $1";   # autocloses, but be paranoid
     $Cache{"${currpack}::<DATA"} = 1;   # indicate package is cached
 
     local($/) = "\n";