mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 15:54:03 +02:00
Fix deadlock when writing to the command pipe while noone is listening
This commit is contained in:
parent
2862c5667c
commit
9066a0c2fa
@ -29,6 +29,8 @@
|
|||||||
|
|
||||||
namespace Icinga\Protocol\Commandpipe\Transport;
|
namespace Icinga\Protocol\Commandpipe\Transport;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Icinga\Util\File;
|
||||||
use Icinga\Logger\Logger;
|
use Icinga\Logger\Logger;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
|
|
||||||
@ -49,7 +51,7 @@ class LocalPipe implements Transport
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $openMode = "w";
|
private $openMode = "wn";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see Transport::setEndpoint()
|
* @see Transport::setEndpoint()
|
||||||
@ -65,13 +67,20 @@ class LocalPipe implements Transport
|
|||||||
public function send($message)
|
public function send($message)
|
||||||
{
|
{
|
||||||
Logger::debug('Attempting to send external icinga command %s to local command file ', $message, $this->path);
|
Logger::debug('Attempting to send external icinga command %s to local command file ', $message, $this->path);
|
||||||
$file = @fopen($this->path, $this->openMode);
|
|
||||||
if (!$file) {
|
try {
|
||||||
throw new ConfigurationError(sprintf('Could not open icinga command pipe at "%s"', $this->path));
|
File::open($this->path, $this->openMode)->write('[' . time() . '] ' . $message . PHP_EOL)->close();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
throw new ConfigurationError(
|
||||||
|
sprintf(
|
||||||
|
'Could not open icinga command pipe at "%s" (%s)',
|
||||||
|
$this->path,
|
||||||
|
$e->getMessage()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
fwrite($file, '[' . time() . '] ' . $message . PHP_EOL);
|
|
||||||
Logger::debug('Writing [' . time() . '] ' . $message . PHP_EOL);
|
Logger::debug('Command sent: [' . time() . '] ' . $message . PHP_EOL);
|
||||||
fclose($file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user