Skip to content

Commit

Permalink
Merge branch '2.3' into 2.7
Browse files Browse the repository at this point in the history
* 2.3:
  [Process] Fix signaling/stopping logic on Windows
  [Yaml] minor CS cleaning
  [Console] do not encode backslashes in console default description
  • Loading branch information
fabpot committed Nov 30, 2015
2 parents d4c8c13 + d9b8d0c commit 13fda1c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Descriptor/TextDescriptor.php
Expand Up @@ -236,10 +236,10 @@ private function writeText($content, array $options = array())
private function formatDefaultValue($default)
{
if (PHP_VERSION_ID < 50400) {
return str_replace('\/', '/', json_encode($default));
return str_replace(array('\/', '\\\\'), array('/', '\\'), json_encode($default));
}

return json_encode($default, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
return str_replace('\\\\', '\\', json_encode($default, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
}

/**
Expand Down
33 changes: 16 additions & 17 deletions src/Symfony/Component/Process/Process.php
Expand Up @@ -775,36 +775,24 @@ public function getStatus()
* Stops the process.
*
* @param int|float $timeout The timeout in seconds
* @param int $signal A POSIX signal to send in case the process has not stop at timeout, default is SIGKILL
* @param int $signal A POSIX signal to send in case the process has not stop at timeout, default is SIGKILL (9)
*
* @return int The exit-code of the process
*
* @throws RuntimeException if the process got signaled
*/
public function stop($timeout = 10, $signal = null)
{
$timeoutMicro = microtime(true) + $timeout;
if ($this->isRunning()) {
if ('\\' === DIRECTORY_SEPARATOR && !$this->isSigchildEnabled()) {
exec(sprintf('taskkill /F /T /PID %d 2>&1', $this->getPid()), $output, $exitCode);
if ($exitCode > 0) {
throw new RuntimeException('Unable to kill the process');
}
}
// given `SIGTERM` may not be defined and that `proc_terminate` uses the constant value and not the constant itself, we use the same here
$this->doSignal(15, false);
do {
usleep(1000);
} while ($this->isRunning() && microtime(true) < $timeoutMicro);

if ($this->isRunning() && !$this->isSigchildEnabled()) {
if (null !== $signal || defined('SIGKILL')) {
// avoid exception here :
// process is supposed to be running, but it might have stop
// just after this line.
// in any case, let's silently discard the error, we can not do anything
$this->doSignal($signal ?: SIGKILL, false);
}
// Avoid exception here: process is supposed to be running, but it might have stopped just
// after this line. In any case, let's silently discard the error, we cannot do anything.
$this->doSignal($signal ?: 9, false);
}
}

Expand Down Expand Up @@ -1473,7 +1461,18 @@ private function doSignal($signal, $throwException)
return false;
}

if (true !== @proc_terminate($this->process, $signal)) {
if ('\\' === DIRECTORY_SEPARATOR) {
exec(sprintf('taskkill /F /T /PID %d 2>&1', $this->getPid()), $output, $exitCode);
if ($exitCode) {
if ($throwException) {
throw new RuntimeException(sprintf('Unable to kill the process (%s).', implode(' ', $output)));
}

return false;
}
}

if (true !== @proc_terminate($this->process, $signal) && '\\' !== DIRECTORY_SEPARATOR) {
if ($throwException) {
throw new RuntimeException(sprintf('Error while sending signal `%s`.', $signal));
}
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -347,7 +347,7 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
if (null === $indentation) {
$newIndent = $this->getCurrentLineIndentation();

$unindentedEmbedBlock = $this->isStringUnIndentedCollectionItem($this->currentLine);
$unindentedEmbedBlock = $this->isStringUnIndentedCollectionItem();

if (!$this->isCurrentLineEmpty() && 0 === $newIndent && !$unindentedEmbedBlock) {
throw new ParseException('Indentation problem.', $this->getRealCurrentLineNb() + 1, $this->currentLine);
Expand All @@ -373,7 +373,7 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
return;
}

$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem($this->currentLine);
$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem();

// Comments must not be removed inside a block scalar
$removeCommentsPattern = '~'.self::BLOCK_SCALAR_HEADER_PATTERN.'$~';
Expand All @@ -386,7 +386,7 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
$removeComments = !preg_match($removeCommentsPattern, $this->currentLine);
}

if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem($this->currentLine) && $newIndent === $indent) {
if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem() && $newIndent === $indent) {
$this->moveToPreviousLine();
break;
}
Expand Down Expand Up @@ -690,7 +690,7 @@ private function isNextLineUnIndentedCollection()
if (
$this->getCurrentLineIndentation() == $currentIndentation
&&
$this->isStringUnIndentedCollectionItem($this->currentLine)
$this->isStringUnIndentedCollectionItem()
) {
$ret = true;
}
Expand Down

0 comments on commit 13fda1c

Please sign in to comment.