From 6f4a68241c95736b87a27821902f52ddc5ba239e Mon Sep 17 00:00:00 2001 From: Laszlo Magyar Date: Sat, 8 Nov 2025 12:52:45 +0100 Subject: [PATCH 1/2] Redirects the $LOG_FD fd to a changed STDOUT --- lib/log.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/log.sh b/lib/log.sh index 5f94701..8264396 100644 --- a/lib/log.sh +++ b/lib/log.sh @@ -15,6 +15,21 @@ if ! [[ "${LOG_FD-}" =~ ^[0-9]+$ ]] || ! { : >&"${LOG_FD-2}"; } 2>/dev/null; the exec {LOG_FD}>&1 fi +# ------------------------------------------------------------------------------ +# Redirects the $LOG_FD fd to a changed STDOUT. +# +# If an add-on script changed the STDOUT (after the $LOG_FD fd was redirected to +# it, see above), this function redirects the $LOG_FD fd to the new STDOUT. +# +# Add-on developers must call this function after changing the STDOUT if they +# want the log functions to log to the new STDOUT. +# ------------------------------------------------------------------------------ +function bashio::log.reinitialize_output() { + if [[ "${LOG_FD:-}" =~ ^[0-9]+$ ]]; then + eval "exec ${LOG_FD}>&1" + fi +} + # ------------------------------------------------------------------------------ # Log a message to output. # From b3804d8e69a1c9b54d0e99c96c87e52c0da51ad3 Mon Sep 17 00:00:00 2001 From: Laszlo Magyar Date: Sat, 8 Nov 2025 13:39:30 +0100 Subject: [PATCH 2/2] adding fd writeability validation for consistency (based on ai review) --- lib/log.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/log.sh b/lib/log.sh index 8264396..a2c216c 100644 --- a/lib/log.sh +++ b/lib/log.sh @@ -25,7 +25,7 @@ fi # want the log functions to log to the new STDOUT. # ------------------------------------------------------------------------------ function bashio::log.reinitialize_output() { - if [[ "${LOG_FD:-}" =~ ^[0-9]+$ ]]; then + if [[ "${LOG_FD:-}" =~ ^[0-9]+$ ]] && { : >&"${LOG_FD}"; } 2>/dev/null; then eval "exec ${LOG_FD}>&1" fi }