From ff58f4c12b67b41d423c4eeca8733cf2bdee462e Mon Sep 17 00:00:00 2001 From: Divarion-D Date: Tue, 17 Mar 2026 20:46:31 +0300 Subject: [PATCH] fix(cli): improve MonitorCommand failure handling and process kill - Use >= instead of == for stop_failures threshold (prevents skipping the exact failure count if incremented past it) - Add retry with sleep on stream start failure before goto label76 - Replace shell_exec('kill -9 `ps ...`') with safer xargs pipeline that handles empty PID lists gracefully (xargs -r) --- src/cli/Commands/MonitorCommand.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cli/Commands/MonitorCommand.php b/src/cli/Commands/MonitorCommand.php index 68e21b4..e45dff5 100644 --- a/src/cli/Commands/MonitorCommand.php +++ b/src/cli/Commands/MonitorCommand.php @@ -248,10 +248,13 @@ class MonitorCommand implements CommandInterface { if ((is_numeric($rData) && ($rData == 0))) { $E9d347a502b13abd = true; $rMaxFails++; - if (((0 < SettingsManager::getAll()['stop_failures']) && ($rMaxFails == SettingsManager::getAll()['stop_failures']))) { + if (((0 < SettingsManager::getAll()['stop_failures']) && ($rMaxFails >= SettingsManager::getAll()['stop_failures']))) { echo "Failure limit reached, exiting.\n"; return 0; } + echo 'Stream start failed (attempt ' . $rMaxFails . '). Sleeping ' . SettingsManager::getAll()['stream_fail_sleep'] . " seconds...\n"; + sleep(SettingsManager::getAll()['stream_fail_sleep']); + goto label76; } if (!$rData) { return 0; @@ -575,7 +578,7 @@ class MonitorCommand implements CommandInterface { } if (empty($rPID)) { - shell_exec("kill -9 `ps -ef | grep 'XC_VM\\[" . intval($rStreamID) . "\\]' | grep -v grep | awk '{print \$2}'`;"); + shell_exec("ps -ef | grep 'XC_VM\\[" . intval($rStreamID) . "\\]' | grep -v grep | awk '{print \$2}' | xargs -r kill -9 2>/dev/null"); } else { if (file_exists('/proc/' . $rPID)) { $rCommand = trim(file_get_contents('/proc/' . $rPID . '/cmdline'));