8000 Remove enhance sigchild compatibility · symfony/symfony@7838da4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7838da4

Browse files
committed
Remove enhance sigchild compatibility
1 parent 7f52292 commit 7838da4

File tree

3 files changed

+37
-105
lines changed

3 files changed

+37
-105
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ install:
158158
echo "$COMPONENTS" | parallel --gnu "tfold {} $PHPUNIT_X {}"
159159
tfold tty-group $PHPUNIT --group tty
160160
if [[ $PHP = $MIN_PHP ]]; then
161-
echo -e "1\\n0" | xargs -I{} bash -c "tfold src/Symfony/Component/Process.sigchild{} SYMFONY_DEPRECATIONS_HELPER=weak ENHANCE_SIGCHLD={} php-$MIN_PHP/sapi/cli/php ./phpunit --colors=always src/Symfony/Component/Process/"
161+
tfold src/Symfony/Component/Process.sigchild SYMFONY_DEPRECATIONS_HELPER=weak php-$MIN_PHP/sapi/cli/php ./phpunit --colors=always src/Symfony/Component/Process/
162162
fi
163163
fi
164164
}

src/Symfony/Component/Process/Process.php

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class Process implements \IteratorAggregate
6464
private $outputDisabled = false;
6565
private $stdout;
6666
private $stderr;
67-
private $enhanceSigchildCompatibility;
6867
private $process;
6968
private $status = self::STATUS_READY;
7069
private $incrementalOutputOffset = 0;
@@ -165,7 +164,6 @@ public function __construct($commandline, $cwd = null, array $env = null, $input
165164
$this->setTimeout($timeout);
166165
$this->useFileHandles = '\\' === DIRECTORY_SEPARATOR;
167166
$this->pty = false;
168-
$this->enhanceSigchildCompatibility = '\\' !== DIRECTORY_SEPARATOR && $this->isSigchildEnabled();
169167
}
170168

171169
public function __destruct()
@@ -218,17 +216,12 @@ public function run($callback = null, array $env = array())
218216
*
219217
* @return self
220218
*
221-
* @throws RuntimeException if PHP was compiled with --enable-sigchild and the enhanced sigchild compatibility mode is not enabled
222219
* @throws ProcessFailedException if the process didn't terminate successfully
223220
*
224221
* @final since version 3.3
225222
*/
226223
public function mustRun(callable $callback = null, array $env = array())
227224
{
228-
if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
229-
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
230-
}
231-
232225
if (0 !== $this->run($callback, $env)) {
233226
throw new ProcessFailedException($this);
234227
}
@@ -297,7 +290,7 @@ public function start(callable $callback = null, array $env = array())
297290
if ('\\' === DIRECTORY_SEPARATOR) {
298291
$options['bypass_shell'] = true;
299292
$commandline = $this->prepareWindowsCommandLine($commandline, $envBackup, $env);
300-
} elseif (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
293+
} elseif (!$this->useFileHandles && $this->isSigchildEnabled()) {
301294
// last exit code is output on the fourth pipe and caught to work around --enable-sigchild
302295
$descriptors[3] = array('pipe', 'w');
303296

@@ -665,15 +658,9 @@ public function clearErrorOutput()
665658
* Returns the exit code returned by the process.
666659
*
667660
* @return null|int The exit status code, null if the Process is not terminated
668-
*
669-
* @throws RuntimeException In case --enable-sigchild is activated and the sigchild compatibility mode is disabled
670661
*/
671662
public function getExitCode()
672663
{
673-
if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
674-
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
675-
}
676-
677664
$this->updateStatus(false);
678665

679666
return $this->exitcode;
@@ -716,17 +703,12 @@ public function isSuccessful()
716703
*
717704
* @return bool
718705
*
719-
* @throws RuntimeException In case --enable-sigchild is activated
720706
* @throws LogicException In case the process is not terminated
721707
*/
722708
public function hasBeenSignaled()
723709
{
724710
$this->requireProcessIsTerminated(__FUNCTION__);
725711

726-
if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
727-
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
728-
}
729-
730712
return $this->processInformation['signaled'];
731713
}
732714

@@ -744,7 +726,7 @@ public function getTermSignal()
744726
{
745727
$this->requireProcessIsTerminated(__FUNCTION__);
746728

747-
if ($this->isSigchildEnabled() && (!$this->enhanceSigchildCompatibility || -1 === $this->processInformation['termsig'])) {
729+
if ($this->isSigchildEnabled() && -1 === $this->processInformation['termsig']) {
748730
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
749731
}
750732

@@ -1153,42 +1135,6 @@ public function setInput($input)
11531135
return $this;
11541136
}
11551137

1156-
/**
1157-
* Returns whether sigchild compatibility mode is activated or not.
1158-
*
1159-
* @return bool
1160-
*
1161-
* @deprecated since version 3.3, to be removed in 4.0. Sigchild compatibility will always be enabled.
1162-
*/
1163-
public function getEnhanceSigchildCompatibility()
1164-
{
1165-
@trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Sigchild compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED);
1166-
1167-
return $this->enhanceSigchildCompatibility;
1168-
}
1169-
1170-
/**
1171-
* Activates sigchild compatibility mode.
1172-
*
1173-
* Sigchild compatibility mode is required to get the exit code and
1174-
* determine the success of a process when PHP has been compiled with
1175-
* the --enable-sigchild option
1176-
*
1177-
* @param bool $enhance
1178-
*
1179-
* @return self The current Process instance
1180-
*
1181-
* @deprecated since version 3.3, to be removed in 4.0.
1182-
*/
1183-
public function setEnhanceSigchildCompatibility($enhance)
1184-
{
1185-
@trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Sigchild compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED);
1186-
1187-
$this->enhanceSigchildCompatibility = (bool) $enhance;
1188-
1189-
return $this;
1190-
}
1191-
11921138
/**
11931139
* Sets whether environment variables will be inherited or not.
11941140
*
@@ -1322,7 +1268,7 @@ protected function updateStatus($blocking)
13221268

13231269
$this->readPipes($running && $blocking, '\\' !== DIRECTORY_SEPARATOR || !$running);
13241270

1325-
if ($this->fallbackStatus && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
1271+
if ($this->fallbackStatus && $this->isSigchildEnabled()) {
13261272
$this->processInformation = $this->fallbackStatus + $this->processInformation;
13271273
}
13281274

@@ -1431,7 +1377,7 @@ private function close()
14311377
if ($this->processInformation['signaled'] && 0 < $this->processInformation['termsig']) {
14321378
// if process has been signaled, no exitcode but a valid termsig, apply Unix convention
14331379
$this->exitcode = 128 + $this->processInformation['termsig'];
1434-
} elseif ($this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
1380+
} elseif ($this->isSigchildEnabled()) {
14351381
$this->processInformation['signaled'] = true;
14361382
$this->processInformation['termsig'] = -1;
14371383
}
@@ -1496,7 +1442,7 @@ private function doSignal($signal, $throwException)
14961442
return false;
14971443
}
14981444
} else {
1499-
if (!$this->enhanceSigchildCompatibility || !$this->isSigchildEnabled()) {
1445+
if (!$this->isSigchildEnabled()) {
15001446
$ok = @proc_terminate($this->process, $signal);
15011447
} elseif (function_exists('posix_kill')) {
15021448
$ok = @posix_kill($pid, $signal);

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 31 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class ProcessTest extends TestCase
2828
private static $phpBin;
2929
private static $process;
3030
private static $sigchild;
31-
private static $notEnhancedSigchild = false;
3231

3332
public static function setUpBeforeClass()
3433
{
@@ -420,7 +419,7 @@ public function testExitCodeCommandFailed()
420419
if ('\\' === DIRECTORY_SEPARATOR) {
421420
$this->markTestSkipped('Windows does not support POSIX exit code');
422421
}
423-
$this->skipIfNotEnhancedSigchild();
422+
$this->skipIfSigchildEnabled();
424423

425424
// such command run in bash return an exitcode 127
426425
$process = $this->getProcess('nonexistingcommandIhopeneversomeonewouldnameacommandlikethis');
@@ -455,7 +454,7 @@ public function testTTYCommandExitCode()
455454
if ('\\' === DIRECTORY_SEPARATOR) {
456455
$this->markTestSkipped('Windows does have /dev/tty support');
457456
}
458-
$this->skipIfNotEnhancedSigchild();
457+
$this->skipIfSigchildEnabled();
459458

460459
$process = $this->getProcess('echo "foo" >> /dev/null');
461460
$process->setTty(true);
@@ -481,7 +480,7 @@ public function testTTYInWindowsEnvironment()
481480

482481
public function testExitCodeTextIsNullWhenExitCodeIsNull()
483482
{
484-
$this->skipIfNotEnhancedSigchild();
483+
$this->skipIfSigchildEnabled();
485484

486485
$process = $this->getProcess('');
487486
$this->assertNull($process->getExitCodeText());
@@ -503,7 +502,7 @@ public function testPTYCommand()
503502

504503
public function testMustRun()
505504
{
506-
$this->skipIfNotEnhancedSigchild();
505+
$this->skipIfSigchildEnabled();
507506

508507
$process = $this->getProcess('echo foo');
509508

@@ -513,7 +512,7 @@ public function testMustRun()
513512

514513
public function testSuccessfulMustRunHasCorrectExitCode()
515514
{
516-
$this->skipIfNotEnhancedSigchild();
515+
$this->skipIfSigchildEnabled();
517516

518517
$process = $this->getProcess('echo foo')->mustRun();
519518
$this->assertEquals(0, $process->getExitCode());
@@ -524,15 +523,15 @@ public function testSuccessfulMustRunHasCorrectExitCode()
524523
*/
525524
public function testMustRunThrowsException()
526525
{
527-
$this->skipIfNotEnhancedSigchild();
526+
$this->skipIfSigchildEnabled();
528527

529528
$process = $this->getProcess('exit 1');
530529
$process->mustRun();
531530
}
532531

533532
public function testExitCodeText()
534533
{
535-
$this->skipIfNotEnhancedSigchild();
534+
$this->skipIfSigchildEnabled();
536535

537536
$process = $this->getProcess('');
538537
$r = new \ReflectionObject($process);
@@ -562,7 +561,7 @@ public function testUpdateStatus()
562561

563562
public function testGetExitCodeIsNullOnStart()
564563
{
565-
$this->skipIfNotEnhancedSigchild();
564+
$this->skipIfSigchildEnabled();
566565

< F438 /div>
567566
$process = $this->getProcessForCode('usleep(100000);');
568567
$this->assertNull($process->getExitCode());
@@ -574,7 +573,7 @@ public function testGetExitCodeIsNullOnStart()
574573

575574
public function testGetExitCodeIsNullOnWhenStartingAgain()
576575
{
577-
$this->skipIfNotEnhancedSigchild();
576+
$this->skipIfSigchildEnabled();
578577

579578
$process = $this->getProcessForCode('usleep(100000);');
580579
$process->run();
@@ -587,7 +586,7 @@ public function testGetExitCodeIsNullOnWhenStartingAgain()
587586

588587
public function testGetExitCode()
589588
{
590-
$this->skipIfNotEnhancedSigchild();
589+
$this->skipIfSigchildEnabled();
591590

592591
$process = $this->getProcess('echo foo');
593592
$process->run();
@@ -624,7 +623,7 @@ public function testStop()
624623

625624
public function testIsSuccessful()
626625
{
627-
$this->skipIfNotEnhancedSigchild();
626+
$this->skipIfSigchildEnabled();
628627

629628
$process = $this->getProcess('echo foo');
630629
$process->run();
@@ -633,7 +632,7 @@ public function testIsSuccessful()
633632

634633
public function testIsSuccessfulOnlyAfterTerminated()
635634
{
636-
$this->skipIfNotEnhancedSigchild();
635+
$this->skipIfSigchildEnabled();
637636

638637
$process = $this->getProcessForCode('usleep(100000);');
639638
$process->start();
@@ -647,7 +646,7 @@ public function testIsSuccessfulOnlyAfterTerminated()
647646

648647
public function testIsNotSuccessful()
649648
{
650-
$this->skipIfNotEnhancedSigchild();
649+
$this->skipIfSigchildEnabled();
651650

652651
$process = $this->getProcessForCode('throw new \Exception(\'BOUM\');');
653652
$process->run();
@@ -659,7 +658,7 @@ public function testProcessIsNotSignaled()
659658
if ('\\' === DIRECTORY_SEPARATOR) {
660659
$this->markTestSkipped('Windows does not support POSIX signals');
661660
}
662-
$this->skipIfNotEnhancedSigchild();
661+
$this->skipIfSigchildEnabled();
663662

664663
$process = $this->getProcess('echo foo');
665664
$process->run();
@@ -671,7 +670,7 @@ public function testProcessWithoutTermSignal()
671670
if ('\\' === DIRECTORY_SEPARATOR) {
672671
$this->markTestSkipped('Windows does not support POSIX signals');
673672
}
674-
$this->skipIfNotEnhancedSigchild();
673+
$this->skipIfSigchildEnabled();
675674

676675
$process = $this->getProcess('echo foo');
677676
$process->run();
@@ -683,7 +682,7 @@ public function testProcessIsSignaledIfStopped()
683682
if ('\\' === DIRECTORY_SEPARATOR) {
684683
$this->markTestSkipped('Windows does not support POSIX signals');
685684
}
686-
$this->skipIfNotEnhancedSigchild();
685+
$this->skipIfSigchildEnabled();
687686

688687
$process = $this->getProcessForCode('sleep(32);');
689688
$process->start();
@@ -701,7 +700,7 @@ public function testProcessThrowsExceptionWhenExternallySignaled()
701700
if (!function_exists('posix_kill')) {
702701
$this->markTestSkipped('Function posix_kill is required.');
703702
}
704-
$this->skipIfNotEnhancedSigchild(false);
703+
$this->skipIfSigchildEnabled(false);
705704

706705
$process = $this->getProcessForCode('sleep(32.1);');
707706
$process->start();
@@ -912,7 +911,7 @@ public function testSignal()
912911
*/
913912
public function testExitCodeIsAvailableAfterSignal()
914913
{
915-
$this->skipIfNotEnhancedSigchild();
914+
$this->skipIfSigchildEnabled();
916915

917916
$process = $this->getProcess('sleep 4');
918917
$process->start();
@@ -1487,21 +1486,6 @@ private function getProcess($commandline, $cwd = null, array $env = null, $input
14871486
$process = new Process($commandline, $cwd, $env, $input, $timeout);
14881487
$process->inheritEnvironmentVariables();
14891488

1490-
if (false !== $enhance = getenv('ENHANCE_SIGCHLD')) {
1491-
try {
1492-
$process->setEnhanceSigchildCompatibility(false);
1493-
$process->getExitCode();
1494-
$this->fail('ENHANCE_SIGCHLD must be used together with a sigchild-enabled PHP.');
1495-
} catch (RuntimeException $e) {
1496-
$this->assertSame('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.', $e->getMessage());
1497-
if ($enhance) {
1498-
$process->setEnhanceSigchildCompatibility(true);
1499-
} else {
1500-
self::$notEnhancedSigchild = true;
1501-
}
1502-
}
1503-
}
1504-
15051489
if (self::$process) {
15061490
self::$process->stop(0);
15071491
}
@@ -1517,19 +1501,21 @@ private function getProcessForCode($code, $cwd = null, array $env = null, $input
15171501
return $this->getProcess(array(self::$phpBin, '-r', $code), $cwd, $env, $input, $timeout);
15181502
}
15191503

1520-
private function skipIfNotEnhancedSigchild($expectException = true)
1504+
private function skipIfSigchildEnabled($expectException = true)
15211505
{
1522-
if (self::$sigchild) {
1523-
if (!$expectException) {
1524-
$this->markTestSkipped('PHP is compiled with --enable-sigchild.');
1525-
} elseif (self::$notEnhancedSigchild) {
1526-
if (method_exists($this, 'expectException')) {
1527-
$this->expectException('Symfony\Component\Process\Exception\RuntimeException');
1528-
$this->expectExceptionMessage('This PHP has been compiled with --enable-sigchild.');
1529-
} else {
1530-
$this->setExpectedException('Symfony\Component\Process\Exception\Runt 9D2F imeException', 'This PHP has been compiled with --enable-sigchild.');
1531-
}
1506+
if (!self::$sigchild) {
1507+
return;
1508+
}
1509+
1510+
if ($expectException) {
1511+
if (method_exists($this, 'expectException')) {
1512+
$this->expectException('Symfony\Component\Process\Exception\RuntimeException');
1513+
$this->expectExceptionMessage('This PHP has been compiled with --enable-sigchild.');
1514+
} else {
1515+
$this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild.');
15321516
}
1517+
} else {
1518+
$this->markTestSkipped('PHP is compiled with --enable-sigchild.');
15331519
}
15341520
}
15351521
}

0 commit comments

Comments
 (0)
0