Shell: Don't hang on empty stdin
If the write buffer for a file descriptor is empty, don't try to write to it. Just close it and continue on. Bug: T188019 Change-Id: Ie5b5ac1ef1aec4ae763cf4d0d58d3a28e42b7d2a
This commit is contained in:
parent
f075c9eb82
commit
86cfcfdbba
2 changed files with 13 additions and 0 deletions
|
|
@ -463,6 +463,12 @@ class Command {
|
|||
$isWrite = array_key_exists( $fd, $readPipes );
|
||||
|
||||
if ( $isWrite ) {
|
||||
// Don't bother writing if the buffer is empty
|
||||
if ( $buffers[$fd] === '' ) {
|
||||
fclose( $pipes[$fd] );
|
||||
unset( $pipes[$fd] );
|
||||
continue;
|
||||
}
|
||||
$res = fwrite( $pipe, $buffers[$fd], 65536 );
|
||||
} else {
|
||||
$res = fread( $pipe, 65536 );
|
||||
|
|
|
|||
|
|
@ -170,5 +170,12 @@ class CommandTest extends PHPUnit\Framework\TestCase {
|
|||
$command->input( str_repeat( '!', 1000000 ) );
|
||||
$result = $command->execute();
|
||||
$this->assertSame( 1000000, strlen( $result->getStdout() ) );
|
||||
|
||||
// And try it with empty input
|
||||
$command = new Command();
|
||||
$command->params( 'cat' );
|
||||
$command->input( '' );
|
||||
$result = $command->execute();
|
||||
$this->assertSame( '', $result->getStdout() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue