Skip to content

Fix GH-12077: Check lsof functionality in socket on close test #12084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sapi/fpm/tests/socket-close-on-exec.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FPM: Set CLOEXEC on the listen and connection socket
--SKIPIF--
<?php
require_once "skipif.inc";
FPM\Tester::skipIfShellCommandFails('lsof -v 2> /dev/null');
FPM\Tester::skipIfShellCommandFails('lsof -v', 'lsof-org/lsof');
?>
--FILE--
<?php
Expand Down
20 changes: 16 additions & 4 deletions sapi/fpm/tests/tester.inc
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,24 @@ class Tester
* Skip test if supplied shell command fails.
*
* @param string $command
* @param string|null $expectedPartOfOutput
*/
static public function skipIfShellCommandFails($command)
static public function skipIfShellCommandFails(string $command, string $expectedPartOfOutput = null)
{
$output = system($command, $code);
if ($code) {
die("skip command '$command' faield with code $code and output: $output");
$result = exec("$command 2>&1", $output, $code);
if ($result === false || $code) {
die("skip command '$command' faieled with code $code");
}
if (!is_null($expectedPartOfOutput)) {
if (is_array($output)) {
foreach ($output as $line) {
if (str_contains($line, $expectedPartOfOutput)) {
// string found so no need to skip
return;
}
}
}
die("skip command '$command' did not contain output '$expectedPartOfOutput'");
}
}

Expand Down