Skip to content

Commit ac1ccce

Browse files
committed
waitpid in ftp server tests
This is not relevant right now, but ensures consistent order if the tests are repeated.
1 parent 8f17d48 commit ac1ccce

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

ext/ftp/tests/server.inc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ $port = (int) substr($socket_name, strrpos($socket_name, ':') + 1);
1616
$pid = pcntl_fork();
1717

1818
if ($pid) {
19-
2019
function dump_and_exit($buf)
2120
{
2221
var_dump($buf);
23-
fclose($GLOBALS['s']);
2422
exit;
2523
}
2624

@@ -54,10 +52,14 @@ if ($pid) {
5452

5553
if (!$s) die("Error accepting a new connection\n");
5654

55+
register_shutdown_function(function() use($pid, $s) {
56+
fclose($s);
57+
pcntl_waitpid($pid, $status);
58+
});
59+
5760
fputs($s, "220----- PHP FTP server 0.3 -----\r\n220 Service ready\r\n");
5861
$buf = fread($s, 2048);
5962

60-
6163
function user_auth($buf) {
6264
global $user, $s, $ssl, $bug37799;
6365

@@ -107,7 +109,6 @@ if ($pid) {
107109
$user = $m[1];
108110
if ($user !== 'user' && $user !== 'anonymous') {
109111
fputs($s, "530 Not logged in.\r\n");
110-
fclose($s);
111112
exit;
112113
}
113114

@@ -127,7 +128,6 @@ if ($pid) {
127128
fputs($s, "230 User logged in\r\n");
128129
} else {
129130
fputs($s, "530 Not logged in.\r\n");
130-
fclose($s);
131131
exit;
132132
}
133133
}
@@ -507,7 +507,6 @@ if ($pid) {
507507
dump_and_exit($buf);
508508
}
509509
}
510-
fclose($s);
511510
exit;
512511
}
513512

0 commit comments

Comments
 (0)