From 2fd94baa054e086841257bce2e0755a314f74ba5 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sun, 6 Sep 2026 23:03:31 +0200 Subject: [PATCH] Make state_thermal() return 0 on success and -1 on failure --- cmdline/state.h | 6 ++++-- cmdline/thermal.c | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/cmdline/state.h b/cmdline/state.h index 0545cd00..368728c8 100644 --- a/cmdline/state.h +++ b/cmdline/state.h @@ -402,9 +402,11 @@ void state_usage_print(struct snapraid_state* state); void state_fscheck(struct snapraid_state* state, const char* ope); /** - * Measure the temperature of all disks + * Measure the temperature of all disks. + * Return 0 if thermal information was successfully gathered, -1 if thermal gathering failed, is not supported, or no valid temperature is available. + * Individual disks without a valid temperature are ignored as long as at least one disk provides a valid temperature. */ -void state_thermal(struct snapraid_state* state, time_t now); +int state_thermal(struct snapraid_state* state, time_t now); /** * Check if the temperature is outside the operating range diff --git a/cmdline/thermal.c b/cmdline/thermal.c index 924b0260..ba1a17c6 100644 --- a/cmdline/thermal.c +++ b/cmdline/thermal.c @@ -117,7 +117,7 @@ struct snapraid_thermal_params fit_thermal_model(const struct snapraid_thermal_p return model; } -void state_thermal(struct snapraid_state* state, time_t now) +int state_thermal(struct snapraid_state* state, time_t now) { tommy_node* i; unsigned j; @@ -126,7 +126,7 @@ void state_thermal(struct snapraid_state* state, time_t now) int ret; if (state->thermal_temperature_limit == 0) - return; + return 0; state_devmap(state); @@ -186,11 +186,11 @@ void state_thermal(struct snapraid_state* state, time_t now) /* on error, just disable thermal gathering */ if (ret != 0) - goto bail; + goto bail_error; /* if the list is empty, it's not supported in this platform */ if (tommy_list_empty(&low)) - goto bail; + goto bail_error; /* report new attribute */ state_attr(state, &low); @@ -215,6 +215,7 @@ void state_thermal(struct snapraid_state* state, time_t now) log_tag("thermal:system:final:%d\n", state->thermal_ambient_temperature); } + int count = 0; int highest_temperature = 0; for (i = tommy_list_head(&low); i != 0; i = i->next) { tommy_node* t; @@ -226,6 +227,8 @@ void state_thermal(struct snapraid_state* state, time_t now) if (temperature < 0) continue; + ++count; + /* search of the entry */ found = 0; for (t = tommy_list_head(&state->thermallist); t != 0; t = t->next) { @@ -293,15 +296,24 @@ void state_thermal(struct snapraid_state* state, time_t now) found->params.rmse, found->params.r_squared, found->params.max_error); } + /* if no valid temperature was collected, report failure */ + if (count == 0) + goto bail_error; + /* always update the highest temperature */ state->thermal_highest_temperature = highest_temperature; log_tag("thermal:highest:%d\n", highest_temperature); log_flush(); -bail: tommy_list_foreach(&high, free); tommy_list_foreach(&low, free); + return 0; + +bail_error: + tommy_list_foreach(&high, free); + tommy_list_foreach(&low, free); + return -1; } int state_thermal_alarm(struct snapraid_state* state)