develooper Front page | perl.perl5.porters | Postings from February 2015

[perl #123775] Args to 'system' not evaluated before forking, making $$ wrong

Thread Previous | Thread Next
Chris Wagner via RT
February 14, 2015 06:21
[perl #123775] Args to 'system' not evaluated before forking, making $$ wrong
Message ID:
I would like to lobby for evaluating all of the arguments that are not literal strings before the fork.  True, $PID is the scenario at hand but there could be any number of cases down the road.  The other obvious example is anything tie()'d.  Spooky action at a distance is bad and I think the expected behavior of anything passed to system(), etc, is to be the value of the expression at that line of the program.  I can think of one secenario where a tie variable returns memory information about the current process.  Definately do not want that in the forked copy.  Forgive me if I didn't see that in the proposed patch.

For the test case, I have a better suggestion.  It will work on any system.

+    my $rv = system $Perl, '-e', 'exit ($ARGV[0] eq $$)', $$;
+    is($rv, 0, 'Pid is as expected in system');
+    skip 'Can\'t load POSIX' if not eval { require POSIX };
+    if (my $child = open my $fh, '-|') { #parent
+        my $pid = <$fh>;
+        is($pid, $child, 'Pid is as expected in openpipe');
+    } 
+    else { #child
+        system $Perl, '-e', 'print $ARGV[0]', $$;
+        POSIX::_exit(0);
+    }

via perlbug:  queue: perl5 status: open

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About