From d8218ab906a479a4ad2a535a8b987c0e127b6677 Mon Sep 17 00:00:00 2001 From: ljm42 Date: Thu, 24 Apr 2025 12:56:55 -0700 Subject: [PATCH 1/2] revert diagnostics changes in #2168 --- emhttp/plugins/dynamix/scripts/diagnostics | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/emhttp/plugins/dynamix/scripts/diagnostics b/emhttp/plugins/dynamix/scripts/diagnostics index 46deed326..db1d55a01 100755 --- a/emhttp/plugins/dynamix/scripts/diagnostics +++ b/emhttp/plugins/dynamix/scripts/diagnostics @@ -26,6 +26,7 @@ $cli = empty($zip); $docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp'); require_once "$docroot/webGui/include/Helpers.php"; +require_once "$docroot/webGui/include/Wrappers.php"; require_once "$docroot/webGui/include/publish.php"; if (is_file('/boot/syslinux/syslinux.cfg')) { @@ -45,15 +46,34 @@ $pools = pools_filter($disks); require_once "$docroot/webGui/include/CustomMerge.php"; function write(...$messages){ - foreach ($messages as $message) publish('diagnostics', $message); + foreach ($messages as $message) { + publish('diagnostics', $message); + } } +// Add error logging function +function log_error($message, $command = '') { + global $diag; + $error_log = "/$diag/logs/diagnostics.error.log"; + $timestamp = date('Y-m-d H:i:s'); + $log_message = "[$timestamp] $message"; + if ($command) { + $log_message .= " (Command: $command)"; + } + file_put_contents($error_log, $log_message . "\n", FILE_APPEND); +} + +// Modify run function to include error logging function run($cmd, &$save=null, $timeout=30) { + global $cli,$diag; // output command for display write($cmd); // execute command with timeout of 30s - exec("LC_ALL=en_US.UTF-8 timeout -s9 $timeout $cmd", $save); - return implode("\n", $save); + exec("timeout -s9 $timeout $cmd 2>&1", $save, $return_code); + if ($return_code !== 0) { + log_error("Command failed with return code $return_code", $cmd); + } + return implode("\n",$save); } function newline($file) { From fef99b9df762e2f200d7632d9e4d272857c66452 Mon Sep 17 00:00:00 2001 From: ljm42 Date: Thu, 24 Apr 2025 12:58:47 -0700 Subject: [PATCH 2/2] fix: diagnostics: ensure commands run with UTF-8 charset --- emhttp/plugins/dynamix/scripts/diagnostics | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emhttp/plugins/dynamix/scripts/diagnostics b/emhttp/plugins/dynamix/scripts/diagnostics index db1d55a01..6193cd106 100755 --- a/emhttp/plugins/dynamix/scripts/diagnostics +++ b/emhttp/plugins/dynamix/scripts/diagnostics @@ -69,7 +69,7 @@ function run($cmd, &$save=null, $timeout=30) { // output command for display write($cmd); // execute command with timeout of 30s - exec("timeout -s9 $timeout $cmd 2>&1", $save, $return_code); + exec("LC_ALL=en_US.UTF-8 timeout -s9 $timeout $cmd 2>&1", $save, $return_code); if ($return_code !== 0) { log_error("Command failed with return code $return_code", $cmd); }