]> granicus.if.org Git - php/commitdiff
waitpid in ftp server tests
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 23 Oct 2020 09:10:21 +0000 (11:10 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 23 Oct 2020 14:56:23 +0000 (16:56 +0200)
This is not relevant right now, but ensures consistent order if
the tests are repeated.

ext/ftp/tests/server.inc

index e220d6f072f29adfde968ecfca700e6b33fd0c46..8bc836fc40e3246e58998c39688685ccae3e97ee 100644 (file)
@@ -16,11 +16,9 @@ $port = (int) substr($socket_name, strrpos($socket_name, ':') + 1);
 $pid = pcntl_fork();
 
 if ($pid) {
-
     function dump_and_exit($buf)
     {
         var_dump($buf);
-        fclose($GLOBALS['s']);
         exit;
     }
 
@@ -54,10 +52,14 @@ if ($pid) {
 
     if (!$s) die("Error accepting a new connection\n");
 
+    register_shutdown_function(function() use($pid, $s) {
+        fclose($s);
+        pcntl_waitpid($pid, $status);
+    });
+
     fputs($s, "220----- PHP FTP server 0.3 -----\r\n220 Service ready\r\n");
     $buf = fread($s, 2048);
 
-
     function user_auth($buf) {
         global $user, $s, $ssl, $bug37799;
 
@@ -107,7 +109,6 @@ if ($pid) {
         $user = $m[1];
         if ($user !== 'user' && $user !== 'anonymous') {
             fputs($s, "530 Not logged in.\r\n");
-            fclose($s);
             exit;
         }
 
@@ -127,7 +128,6 @@ if ($pid) {
                 fputs($s, "230 User logged in\r\n");
             } else {
                 fputs($s, "530 Not logged in.\r\n");
-                fclose($s);
                 exit;
             }
         }
@@ -507,7 +507,6 @@ if ($pid) {
             dump_and_exit($buf);
         }
     }
-    fclose($s);
     exit;
 }