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
From:
Chris Wagner via RT
Date:
February 14, 2015 06:21
Subject:
[perl #123775] Args to 'system' not evaluated before forking, making $$ wrong
Message ID:
rt-4.0.18-25317-1423889279-383.123775-15-0@perl.org
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.


<code>
+    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);
+    }
</code>





---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=123775

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About