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.
This commit is contained in:
parent
de10ec949e
commit
334b8c727f
1 changed files with 10 additions and 6 deletions
|
|
@ -825,8 +825,9 @@ get_cached_smart() {
|
||||||
# Cache miss or stale - return empty array and trigger background refresh
|
# Cache miss or stale - return empty array and trigger background refresh
|
||||||
echo "[]"
|
echo "[]"
|
||||||
|
|
||||||
# Trigger async refresh if not already running
|
# Trigger async refresh if not already running (use lock file)
|
||||||
if ! pgrep -f "pulse-sensor-wrapper-refresh" >/dev/null 2>&1; then
|
local lock_file="$CACHE_DIR/smart-refresh.lock"
|
||||||
|
if ! [ -f "$lock_file" ]; then
|
||||||
(refresh_smart_cache &)
|
(refresh_smart_cache &)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -835,11 +836,14 @@ get_cached_smart() {
|
||||||
|
|
||||||
# Function to refresh SMART cache in background
|
# Function to refresh SMART cache in background
|
||||||
refresh_smart_cache() {
|
refresh_smart_cache() {
|
||||||
# Mark this process for detection
|
local lock_file="$CACHE_DIR/smart-refresh.lock"
|
||||||
exec -a pulse-sensor-wrapper-refresh bash
|
|
||||||
|
|
||||||
local cache_file="$CACHE_DIR/smart-temps.json"
|
local cache_file="$CACHE_DIR/smart-temps.json"
|
||||||
local temp_file="${cache_file}.tmp.$$"
|
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=()
|
local disks=()
|
||||||
|
|
||||||
# Find all physical disks (skip partitions, loop devices, etc.)
|
# Find all physical disks (skip partitions, loop devices, etc.)
|
||||||
|
|
@ -856,7 +860,7 @@ refresh_smart_cache() {
|
||||||
# timeout: prevent hanging on problematic drives
|
# timeout: prevent hanging on problematic drives
|
||||||
|
|
||||||
local output
|
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
|
# Parse the JSON output
|
||||||
local temp=$(echo "$output" | jq -r '
|
local temp=$(echo "$output" | jq -r '
|
||||||
.temperature.current //
|
.temperature.current //
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue