Skip to content

Commit 5544c11

Browse files
committed
remove async
1 parent 515201e commit 5544c11

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

LibreNMS/RRD/RrdProcess.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ public function stop(): void
6161
*/
6262
public function run(string $command, string $waitFor = self::COMMAND_COMPLETE): string
6363
{
64-
$this->runAsync($command);
64+
$this->sendCommand($command);
6565

66-
$this->process->clearOutput();
67-
$this->process->waitUntil(function ($type, $buffer) use ($waitFor) {
66+
$output = '';
67+
$this->process->waitUntil(function ($type, $buffer) use ($waitFor, &$output) {
6868
if ($type === Process::ERR) {
6969
throw new RrdException($buffer);
7070
}
@@ -74,19 +74,22 @@ public function run(string $command, string $waitFor = self::COMMAND_COMPLETE):
7474
throw new RrdException($matches[1]);
7575
}
7676

77-
return str_contains($buffer, $waitFor);
77+
$output .= $buffer;
78+
79+
return str_contains($output, $waitFor);
7880
});
7981

80-
$output = $this->process->getOutput();
82+
$this->process->clearOutput();
8183

8284
if ($waitFor === self::COMMAND_COMPLETE) {
83-
$output = substr($output, 0, strrpos($output, $waitFor)); // remove OK line
85+
$pos = strpos($output, self::COMMAND_COMPLETE);
86+
$output = substr($output, 0, $pos);
8487
}
8588

8689
return rtrim($output);
8790
}
8891

89-
public function runAsync(string $command): void
92+
private function sendCommand(string $command): void
9093
{
9194
$this->start();
9295

0 commit comments

Comments
 (0)