1
0
mirror of https://github.com/php/pie.git synced 2026-03-23 23:12:17 +01:00

Merge pull request #426 from asgrim/remove-timeouts-on-processes-except-sudo

Remove timeouts on all process invocations except those potentially using sudo
This commit is contained in:
James Titcumb
2025-11-24 16:16:16 +00:00
committed by GitHub
12 changed files with 26 additions and 33 deletions

View File

@@ -26,10 +26,6 @@ use const DIRECTORY_SEPARATOR;
/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
final class UnixBuild implements Build
{
private const PHPIZE_TIMEOUT_SECS = 60; // 1 minute
private const CONFIGURE_TIMEOUT_SECS = 120; // 2 minutes
private const MAKE_TIMEOUT_SECS = null; // unlimited
/** {@inheritDoc} */
public function __invoke(
DownloadedPackage $downloadedPackage,
@@ -137,8 +133,7 @@ final class UnixBuild implements Build
Process::run(
$phpizeCommand,
$downloadedPackage->extractedSourcePath,
self::PHPIZE_TIMEOUT_SECS,
$outputCallback,
outputCallback: $outputCallback,
);
}
@@ -162,8 +157,7 @@ final class UnixBuild implements Build
Process::run(
$configureCommand,
$downloadedPackage->extractedSourcePath,
self::CONFIGURE_TIMEOUT_SECS,
$outputCallback,
outputCallback: $outputCallback,
);
}
@@ -195,8 +189,7 @@ final class UnixBuild implements Build
Process::run(
$makeCommand,
$downloadedPackage->extractedSourcePath,
self::MAKE_TIMEOUT_SECS,
$outputCallback,
outputCallback: $outputCallback,
);
}
@@ -231,8 +224,7 @@ final class UnixBuild implements Build
Process::run(
$phpizeCleanCommand,
$downloadedPackage->extractedSourcePath,
self::PHPIZE_TIMEOUT_SECS,
$outputCallback,
outputCallback: $outputCallback,
);
$io->write('<info>Build files cleaned up.</info>');

View File

@@ -124,7 +124,7 @@ class PhpBinaryPathBasedPlatformRepository extends PlatformRepository
private function detectLibraryWithPkgConfig(string $alias, string $library): void
{
try {
$pkgConfigResult = Process::run(['pkg-config', '--print-provides', '--print-errors', $library], timeout: 30);
$pkgConfigResult = Process::run(['pkg-config', '--print-provides', '--print-errors', $library]);
} catch (ProcessFailedException) {
return;
}

View File

@@ -51,7 +51,7 @@ final class SudoCreate
}
try {
Process::run([Sudo::find(), 'touch', $filename]);
Process::run([Sudo::find(), 'touch', $filename], timeout: Process::SHORT_TIMEOUT);
} catch (ProcessFailedException $processFailedException) {
throw FailedToCreateFile::fromSudoTouchProcessFailed($filename, $processFailedException);
}

View File

@@ -66,7 +66,7 @@ final class SudoFilePut
self::copyOwnership($filename, $tempFilename);
}
Process::run([Sudo::find(), 'mv', $tempFilename, $filename]);
Process::run([Sudo::find(), 'mv', $tempFilename, $filename], timeout: Process::SHORT_TIMEOUT);
}
/**
@@ -77,18 +77,18 @@ final class SudoFilePut
{
try {
// GNU chmod supports `--reference`, so try this first
Process::run([Sudo::find(), 'chmod', '--reference=' . $sourceFile, $targetFile]);
Process::run([Sudo::find(), 'chmod', '--reference=' . $sourceFile, $targetFile], timeout: Process::SHORT_TIMEOUT);
return;
} catch (ProcessFailedException) {
// Fall back to using `stat` to determine uid/gid
try {
// Try using GNU stat (-c) first
$userAndGroup = Process::run(['stat', '-c', '%u:%g', $sourceFile], timeout: 2);
$userAndGroup = Process::run(['stat', '-c', '%u:%g', $sourceFile]);
} catch (ProcessFailedException) {
try {
// Fall back to using OSX stat (-f)
$userAndGroup = Process::run(['stat', '-f', '%u:%g', $sourceFile], timeout: 2);
$userAndGroup = Process::run(['stat', '-f', '%u:%g', $sourceFile]);
} catch (ProcessFailedException) {
return;
}
@@ -98,7 +98,7 @@ final class SudoFilePut
return;
}
Process::run([Sudo::find(), 'chown', $userAndGroup, $targetFile]);
Process::run([Sudo::find(), 'chown', $userAndGroup, $targetFile], timeout: Process::SHORT_TIMEOUT);
}
}
}

View File

@@ -47,7 +47,7 @@ final class SudoUnlink
}
try {
Process::run([Sudo::find(), 'rm', $filename]);
Process::run([Sudo::find(), 'rm', $filename], timeout: Process::SHORT_TIMEOUT);
} catch (ProcessFailedException $processFailedException) {
throw FailedToUnlinkFile::fromSudoRmProcessFailed($filename, $processFailedException);
}

View File

@@ -166,7 +166,7 @@ final class OndrejPhpenmod implements SetupIniApproach
array_unshift($processArgs, Sudo::find());
}
Process::run($processArgs);
Process::run($processArgs, timeout: Process::SHORT_TIMEOUT);
return true;
} catch (ProcessFailedException $processFailedException) {

View File

@@ -60,8 +60,7 @@ class InstallSelectedPackage
Process::run(
$process,
getcwd(),
null,
static function (string $outOrErr, string $message) use ($io): void {
outputCallback: static function (string $outOrErr, string $message) use ($io): void {
if ($outOrErr === \Symfony\Component\Process\Process::ERR) {
$io->writeError(' > ' . $message);

View File

@@ -46,7 +46,7 @@ class UninstallUsingUnlink implements Uninstall
// If the target directory isn't writable, or a .so file already exists and isn't writable, try to use sudo
if (file_exists($expectedBinaryFile->filePath) && ! is_writable($expectedBinaryFile->filePath) && Sudo::exists()) {
Process::run([Sudo::find(), 'rm', $expectedBinaryFile->filePath]);
Process::run([Sudo::find(), 'rm', $expectedBinaryFile->filePath], timeout: Process::SHORT_TIMEOUT);
// Removal worked, bail out
if (! file_exists($expectedBinaryFile->filePath)) {

View File

@@ -19,9 +19,8 @@ use function str_starts_with;
/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
final class GithubCliAttestationVerification implements VerifyPiePhar
{
private const GH_CLI_NAME = 'gh';
private const GH_ATTESTATION_COMMAND = 'attestation';
private const GH_VERIFICATION_TIMEOUT = 30;
private const GH_CLI_NAME = 'gh';
private const GH_ATTESTATION_COMMAND = 'attestation';
public function __construct(private readonly ExecutableFinder $executableFinder)
{
@@ -37,7 +36,7 @@ final class GithubCliAttestationVerification implements VerifyPiePhar
// Try to use `gh attestation --help` to ensure it is not an old `gh` cli version
try {
Process::run([$gh, self::GH_ATTESTATION_COMMAND, '--help'], null, self::GH_VERIFICATION_TIMEOUT);
Process::run([$gh, self::GH_ATTESTATION_COMMAND, '--help']);
} catch (ProcessFailedException $attestationCommandCheck) {
if (str_starts_with($attestationCommandCheck->getProcess()->getErrorOutput(), sprintf('unknown command "%s" for "%s"', self::GH_ATTESTATION_COMMAND, self::GH_CLI_NAME))) {
throw GithubCliNotAvailable::withMissingAttestationCommand(self::GH_CLI_NAME);
@@ -60,7 +59,7 @@ final class GithubCliAttestationVerification implements VerifyPiePhar
);
try {
Process::run($verificationCommand, null, self::GH_VERIFICATION_TIMEOUT);
Process::run($verificationCommand);
} catch (ProcessFailedException $processFailedException) {
throw FailedToVerifyRelease::fromGhCliFailure($releaseMetadata, $processFailedException);
}

View File

@@ -12,6 +12,9 @@ use function trim;
/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
final class Process
{
public const NO_TIMEOUT = null;
public const SHORT_TIMEOUT = 10;
private function __construct()
{
}
@@ -33,7 +36,7 @@ final class Process
public static function run(
array $command,
string|null $workingDirectory = null,
int|null $timeout = 5,
int|null $timeout = self::NO_TIMEOUT,
callable|null $outputCallback = null,
): string {
return trim((new SymfonyProcess($command, $workingDirectory, timeout: $timeout))

View File

@@ -61,8 +61,8 @@ foreach ($packageNames as $packageName) {
}
}
echo Process::run([$phpBinaryPath->phpBinaryPath, '-m'], timeout: 60);
echo Process::run(['bin/pie', 'show', '--with-php-config=' . $phpBinaryPath->phpConfigPath()], timeout: 60);
echo Process::run([$phpBinaryPath->phpBinaryPath, '-m']);
echo Process::run(['bin/pie', 'show', '--with-php-config=' . $phpBinaryPath->phpConfigPath()]);
if ($anyFailures) {
exit(1);

View File

@@ -188,7 +188,7 @@ final class PhpBinaryPathBasedPlatformRepositoryTest extends TestCase
],
static function (array $pkg): bool {
try {
Process::run(['pkg-config', '--print-provides', '--print-errors', $pkg[1]], timeout: 30);
Process::run(['pkg-config', '--print-provides', '--print-errors', $pkg[1]]);
return true;
} catch (ProcessFailedException) {