Skip to content

Commit fe30c50

Browse files
committed
Fix GH-12077: Check lsof functionality in socket on close test
Closes GH-12084
1 parent 02b3fb1 commit fe30c50

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ PHP NEWS
55
- Core:
66
. Fixed GH-11847 (DTrace enabled build is broken). (Filip Zrůst)
77

8+
- FPM:
9+
. Fixed GH-12077 (PHP 8.3.0RC1 borked socket-close-on-exec.phpt).
10+
(Jakub Zelenka)
11+
812
31 Aug 2023, PHP 8.3.0RC1
913

1014
- Core:

sapi/fpm/tests/socket-close-on-exec.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FPM: Set CLOEXEC on the listen and connection socket
33
--SKIPIF--
44
<?php
55
require_once "skipif.inc";
6-
FPM\Tester::skipIfShellCommandFails('lsof -v 2> /dev/null');
6+
FPM\Tester::skipIfShellCommandFails('lsof -v', 'lsof-org/lsof');
77
?>
88
--FILE--
99
<?php

sapi/fpm/tests/tester.inc

+16-4
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,24 @@ class Tester
342342
* Skip test if supplied shell command fails.
343343
*
344344
* @param string $command
345+
* @param string|null $expectedPartOfOutput
345346
*/
346-
static public function skipIfShellCommandFails($command)
347+
static public function skipIfShellCommandFails(string $command, string $expectedPartOfOutput = null)
347348
{
348-
$output = system($command, $code);
349-
if ($code) {
350-
die("skip command '$command' faield with code $code and output: $output");
349+
$result = exec("$command 2>&1", $output, $code);
350+
if ($result === false || $code) {
351+
die("skip command '$command' faieled with code $code");
352+
}
353+
if (!is_null($expectedPartOfOutput)) {
354+
if (is_array($output)) {
355+
foreach ($output as $line) {
356+
if (str_contains($line, $expectedPartOfOutput)) {
357+
// string found so no need to skip
358+
return;
359+
}
360+
}
361+
}
362+
die("skip command '$command' did not contain output '$expectedPartOfOutput'");
351363
}
352364
}
353365

0 commit comments

Comments
 (0)