aboutsummaryrefslogtreecommitdiffstats
path: root/failsafe.c
diff options
context:
space:
mode:
authorPA4WDH2023-05-21 11:01:50 +0200
committerPA4WDH2023-05-21 11:01:50 +0200
commitda1b103a50732804bec48429523011322eb1acf5 (patch)
tree1f1c73a56393a2b151f7751fc603ab017a05de71 /failsafe.c
parentAdd input validation (diff)
downloadcputemp2maxfreq-da1b103a50732804bec48429523011322eb1acf5.tar.gz
cputemp2maxfreq-da1b103a50732804bec48429523011322eb1acf5.tar.bz2
cputemp2maxfreq-da1b103a50732804bec48429523011322eb1acf5.zip
Improve error handling
Diffstat (limited to 'failsafe.c')
-rw-r--r--failsafe.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/failsafe.c b/failsafe.c
index 3b9fe48..fec00e8 100644
--- a/failsafe.c
+++ b/failsafe.c
@@ -10,24 +10,23 @@ extern struct s_config config;
void failsafe(int code)
{
- printf("Failed to set governor, error %d (%s).\n",errno,strerror(errno));
-
-// We failed to set the governor, try to fail safe. First try the CPU minimum
-// frequency, if that doesn't work out try the fallback frequency
- if (cpufreq_set_long_int("scaling_max_freq",cpudata.min_freq,100)==0)
+// First try to set the CPU to it's minimum frequency
+ if (cpufreq_set_long_int("scaling_max_freq",cpudata.min_freq,100)>0)
{
- printf("Set scaling frequency to CPU's minimum frequency.");
+ printf("Set scaling frequency to CPU's minimum frequency.\n");
exit(code);
}
printf("Failed to set scaling frequency to CPU's minimum frequency, error: %d (%s).\n",errno,strerror(errno));
- if (cpufreq_set_long_int("scaling_max_freq",config.fallback_freq,100)==0)
+// If that failed, try the fallback frequency
+ if (cpufreq_set_long_int("scaling_max_freq",config.fallback_freq,100)>0)
{
- printf("Set scaling frequency to fallback frequency.");
+ printf("Set scaling frequency to fallback frequency.\n");
exit(code);
}
printf("Failed to set scaling frequency to fallback frequency, error: %d (%s).\n",errno,strerror(errno));
+// Everything failed, issue a warning
printf("All safety measures failed, watch out not to fry your hardware.\n");
exit(code);
}