aboutsummaryrefslogtreecommitdiffstats
path: root/failsafe.c
diff options
context:
space:
mode:
authorPA4WDH2024-08-24 12:43:34 +0200
committerPA4WDH2024-08-24 12:43:34 +0200
commita13b6a07822e9807af50bd67bfe64ccba03b5b00 (patch)
tree125b82a0e3cf114fce7522ccd1ef1ebdc936d5c3 /failsafe.c
parentAdd ebuild for version 0.5 (diff)
downloadcputemp2maxfreq-a13b6a07822e9807af50bd67bfe64ccba03b5b00.tar.gz
cputemp2maxfreq-a13b6a07822e9807af50bd67bfe64ccba03b5b00.tar.bz2
cputemp2maxfreq-a13b6a07822e9807af50bd67bfe64ccba03b5b00.zip
Add -k option to keep state on successul exit
Diffstat (limited to 'failsafe.c')
-rw-r--r--failsafe.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/failsafe.c b/failsafe.c
index 59d9d15..b723457 100644
--- a/failsafe.c
+++ b/failsafe.c
@@ -14,23 +14,31 @@ void failsafe(int code)
// Close CSV log if used
if (config.csvfile!=NULL) csvlog_close();
-// First try to set the CPU to it's minimum frequency
- if (cpufreq_set_long_int("scaling_max_freq",cpudata.min_freq,100)>0)
+ if (((config.keepstate==1) && (code!=0)) || config.keepstate==0)
{
- config.logger("Set scaling frequency to CPU's minimum frequency");
- exit(code);
- }
- config.logger("Failed to set scaling frequency to CPU's minimum frequency, error: %d (%s)",errno,strerror(errno));
+
+// First try to set the CPU to it's minimum frequency
+ if (cpufreq_set_long_int("scaling_max_freq",cpudata.min_freq,100)>0)
+ {
+ config.logger("Set scaling frequency to CPU's minimum frequency");
+ exit(code);
+ }
+ config.logger("Failed to set scaling frequency to CPU's minimum frequency, error: %d (%s)",errno,strerror(errno));
// If that failed, try the fallback frequency
- if (cpufreq_set_long_int("scaling_max_freq",config.fallback_freq,100)>0)
- {
- config.logger("Set scaling frequency to fallback frequency");
- exit(code);
+ if (cpufreq_set_long_int("scaling_max_freq",config.fallback_freq,100)>0)
+ {
+ config.logger("Set scaling frequency to fallback frequency");
+ exit(code);
+ }
+ config.logger("Failed to set scaling frequency to fallback frequency, error: %d (%s)",errno,strerror(errno));
+
+// Everything failed, issue a warning
+ config.logger("All safety measures failed, watch out not to fry your hardware");
+ } else {
+// User asked for no action
+ config.logger("Keeping current state due to -k option");
}
- config.logger("Failed to set scaling frequency to fallback frequency, error: %d (%s)",errno,strerror(errno));
-// Everything failed, issue a warning
- config.logger("All safety measures failed, watch out not to fry your hardware");
exit(code);
}