From 334b8c727f2979b3b566a46916e4549d42456cda Mon Sep 17 00:00:00 2001 From: rcourtman Date: Sat, 8 Nov 2025 23:40:43 +0000 Subject: [PATCH] Fix SMART temperature collection on smartctl 7.4+ (related to #672) Fixes two critical bugs in refresh_smart_cache() that prevented SMART temperature collection from working: 1. Invalid smartctl parameter: Changed -n standby,after to -n standby The 'after' parameter is not valid in smartctl 7.4 and causes: "INVALID ARGUMENT TO -n: standby,after" Valid syntax is standby[,STATUS[,STATUS2]] where STATUS must be numeric. 2. Broken process detection: Replaced exec -a with lock file approach The original exec -a pulse-sensor-wrapper-refresh bash line replaced the subshell with a new bash process that had no script to run, causing the function to exit immediately without collecting any SMART data. New approach uses a lock file ($CACHE_DIR/smart-refresh.lock) with trap-based cleanup to prevent concurrent refresh operations. Credits to @ZaDarkSide for identifying these issues in PR #672. --- scripts/install-sensor-proxy.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/install-sensor-proxy.sh b/scripts/install-sensor-proxy.sh index da361b3..0b08e12 100755 --- a/scripts/install-sensor-proxy.sh +++ b/scripts/install-sensor-proxy.sh @@ -825,8 +825,9 @@ get_cached_smart() { # Cache miss or stale - return empty array and trigger background refresh echo "[]" - # Trigger async refresh if not already running - if ! pgrep -f "pulse-sensor-wrapper-refresh" >/dev/null 2>&1; then + # Trigger async refresh if not already running (use lock file) + local lock_file="$CACHE_DIR/smart-refresh.lock" + if ! [ -f "$lock_file" ]; then (refresh_smart_cache &) fi @@ -835,11 +836,14 @@ get_cached_smart() { # Function to refresh SMART cache in background refresh_smart_cache() { - # Mark this process for detection - exec -a pulse-sensor-wrapper-refresh bash - + local lock_file="$CACHE_DIR/smart-refresh.lock" local cache_file="$CACHE_DIR/smart-temps.json" local temp_file="${cache_file}.tmp.$$" + + # Create lock file and ensure cleanup on exit + touch "$lock_file" 2>/dev/null || return 1 + trap "rm -f '$lock_file' '$temp_file'" EXIT + local disks=() # Find all physical disks (skip partitions, loop devices, etc.) @@ -856,7 +860,7 @@ refresh_smart_cache() { # timeout: prevent hanging on problematic drives local output - if output=$(timeout ${MAX_SMARTCTL_TIME}s smartctl -n standby,after -A --json=o "$dev" 2>/dev/null); then + if output=$(timeout ${MAX_SMARTCTL_TIME}s smartctl -n standby -A --json=o "$dev" 2>/dev/null); then # Parse the JSON output local temp=$(echo "$output" | jq -r ' .temperature.current //