Title: [247808] trunk/Tools
Revision
247808
Author
[email protected]
Date
2019-07-24 19:00:37 -0700 (Wed, 24 Jul 2019)

Log Message

[webkitperl] runCommand doesn't work in Windows Perl
https://bugs.webkit.org/show_bug.cgi?id=199900

Reviewed by Don Olmstead.

runCommand was always failing implicit fork by using 'open' with
'-|' in Windows Perl. Explicitly specify the command to 'open' not
to do the implicit fork.

There is one more difference between Windows and Unix. 'open'
successes on Windows even for non existent command while it fails
on Unix. So, return the same error code on Unix as well as
Windows.

* Scripts/VCSUtils.pm: Specified the command to 'open'.
* Scripts/webkitperl/VCSUtils_unittest/runCommand.pl: 'echo'
command is not available on Windows. Use Perl ($^X) instead.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (247807 => 247808)


--- trunk/Tools/ChangeLog	2019-07-25 01:18:03 UTC (rev 247807)
+++ trunk/Tools/ChangeLog	2019-07-25 02:00:37 UTC (rev 247808)
@@ -1,3 +1,23 @@
+2019-07-24  Fujii Hironori  <[email protected]>
+
+        [webkitperl] runCommand doesn't work in Windows Perl
+        https://bugs.webkit.org/show_bug.cgi?id=199900
+
+        Reviewed by Don Olmstead.
+
+        runCommand was always failing implicit fork by using 'open' with
+        '-|' in Windows Perl. Explicitly specify the command to 'open' not
+        to do the implicit fork.
+
+        There is one more difference between Windows and Unix. 'open'
+        successes on Windows even for non existent command while it fails
+        on Unix. So, return the same error code on Unix as well as
+        Windows.
+
+        * Scripts/VCSUtils.pm: Specified the command to 'open'.
+        * Scripts/webkitperl/VCSUtils_unittest/runCommand.pl: 'echo'
+        command is not available on Windows. Use Perl ($^X) instead.
+
 2019-07-24  Priyanka Agarwal  <[email protected]>
 
         Allow Clients to Add Fields to the AutoFillContext Dictionary.

Modified: trunk/Tools/Scripts/VCSUtils.pm (247807 => 247808)


--- trunk/Tools/Scripts/VCSUtils.pm	2019-07-25 01:18:03 UTC (rev 247807)
+++ trunk/Tools/Scripts/VCSUtils.pm	2019-07-25 02:00:37 UTC (rev 247808)
@@ -2398,26 +2398,20 @@
 
 sub runCommand(@)
 {
-    my @args = @_;
-    my $pid = open(CHILD, "-|");
-    if (!defined($pid)) {
-        die "Failed to fork(): $!";
+    # FIXME: Consider further hardening of this function, including sanitizing the environment.
+    my $ok = open(CHILD, "-|", @_);
+    if (!$ok) {
+        return { exitStatus => 1 };
     }
-    if ($pid) {
-        # Parent process
-        my $childStdout;
-        while (<CHILD>) {
-            $childStdout .= $_;
-        }
-        close(CHILD);
-        my %childOutput;
-        $childOutput{exitStatus} = exitStatus($?);
-        $childOutput{stdout} = $childStdout if $childStdout;
-        return \%childOutput;
+    my $childStdout;
+    while (<CHILD>) {
+        $childStdout .= $_;
     }
-    # Child process
-    # FIXME: Consider further hardening of this function, including sanitizing the environment.
-    exec { $args[0] } @args or die "Failed to exec(): $!";
+    close(CHILD);
+    my %childOutput;
+    $childOutput{exitStatus} = exitStatus($?);
+    $childOutput{stdout} = $childStdout if $childStdout;
+    return \%childOutput;
 }
 
 sub gitCommitForSVNRevision

Modified: trunk/Tools/Scripts/webkitperl/VCSUtils_unittest/runCommand.pl (247807 => 247808)


--- trunk/Tools/Scripts/webkitperl/VCSUtils_unittest/runCommand.pl	2019-07-25 01:18:03 UTC (rev 247807)
+++ trunk/Tools/Scripts/webkitperl/VCSUtils_unittest/runCommand.pl	2019-07-25 02:00:37 UTC (rev 247808)
@@ -30,26 +30,24 @@
 use Test::More;
 use VCSUtils;
 
-use constant ENOENT => 2; # See <errno.h>
-
 # The array of test cases.
 my @testCaseHashRefs = (
 {
     # New test
     testName => "Simple",
-    inputArgs => ["echo", "hello"],
+    inputArgs => [$^X, "-e", "print \@ARGV", "hello"],
     expectedReturn => {
         exitStatus => 0,
-        stdout => "hello\n"
+        stdout => "hello"
     }
 },
 {
     # New test
     testName => "Multiple commands",
-    inputArgs => ["echo", "first-command;echo second-command"],
+    inputArgs => [$^X, "-e", "print \@ARGV", "first-command;echo second-command"],
     expectedReturn => {
         exitStatus => 0,
-        stdout => "first-command;echo second-command\n"
+        stdout => "first-command;echo second-command"
     }
 },
 {
@@ -57,7 +55,7 @@
     testName => "Non-existent command",
     inputArgs => ["/usr/bin/non-existent-command"],
     expectedReturn => {
-        exitStatus => ENOENT
+        exitStatus => 1
     }
 }
 );
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to