-.TH "BREEZED" "1"
+.TH "BREEZED" "1.4" "Mar 2010" "Francois Fleuret" "System Deamons"
.SH "NAME"
breezed - Fan control daemon
.SH "SYNOPSIS"
speed one level below. This two degree gap avoids too many
oscillations. Also, the daemon waits for at least 30s after any change
of the fan speed before reducing it. The fan speed is set by writing
-"level <level>" into the specified fan file.
+"level <speed_name>" into the specified fan file. The speed name is
+the leve itself if no alternative is provided with the temperature
+threshold.
Options can not be specified twice, neither on the command line nor in
the configuration file.
set the files to spool for temperatures.
.IP "\fB-ff | --fan-file <file>\fP" 10
set the file to control the fan speed.
-.IP "\fB-tt | --temperature-thresholds <temp1>[,temp2]...\fP" 10
+.IP "\fB-tt | --temperature-thresholds <temp1>[:<speed_name_1>][,temp2[:speed_name_2]]...\fP" 10
set the temperature thresholds.
.SH "CONFIGURATION FILE"
breezed --no-configuration-file \
--thermal-files /proc/acpi/thermal_zone/THM0/temperature,/proc/acpi/thermal_zone/THM1/temperature \
--fan-file /proc/acpi/ibm/fan \
- --temperature-thresholds 52,54,56,58,60,62,64
+ --temperature-thresholds 52,54,56,58,60,62,64,68:full-speed
which specifies that when the temperature raises above 52C, the fan
level should be 1, when the temperature raises above 54C it should be
-2, etc. The maximum speed level 7 should be chosen for temperatures
-above 64C.
+2, etc. The maximum speed level 8 should be chosen for temperatures
+above 68C, and its name is "full-speed" (since no other speed name is
+provided, the other ones are the default level names, hence their
+numerical value).
Due to the two degrees gap between the thresholds to increase and the
thresholds to decrease the temperature, it will for instance remains
breezed is a fan speed control daemon for Linux computers.
- Copyright (c) 2008, 2009 Francois Fleuret
+ Copyright (c) 2008, 2009, 2010 Francois Fleuret
Written by Francois Fleuret <francois@fleuret.org>
This file is part of breezed.
#include <string.h>
const int major_version_number = 1;
-const int minor_version_number = 3;
+const int minor_version_number = 4;
const int buffer_size = 1024;
int nb_temperature_thresholds;
int *temperature_thresholds = 0;
+char **speed_names = 0;
int nb_file_thermal = 0;
char **file_thermal = 0;
char *configuration_file;
+/********************************************************************/
+
+/* malloc with error checking. */
+
+void *safe_malloc(size_t n) {
+ void *p = malloc(n);
+ if (!p && n != 0) {
+ fprintf(stderr, "Can not allocate memory: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ return p;
+}
+
/******************************************************************/
char *next_word(char *buffer, char *r, int buffer_size) {
void set_fan_level(int fan_fd, int f, int max_fan_level) {
char buffer[buffer_size];
if(f < 0 || f > max_fan_level) f = max_fan_level;
- sprintf(buffer, "level %d\n", f);
+ sprintf(buffer, "level %s\n", speed_names[f]);
if(write(fan_fd, buffer, strlen(buffer)) < 0) {
fprintf(stderr, "Error in setting the fan level (%s).\n",
strerror(errno));
nb_file_thermal++;
}
- file_thermal = (char **) malloc(nb_file_thermal * sizeof(char *));
- file_thermal_fd = (int *) malloc(nb_file_thermal * sizeof(int));
+ file_thermal = safe_malloc(nb_file_thermal * sizeof(char *));
+ file_thermal_fd = safe_malloc(nb_file_thermal * sizeof(int));
s = definition;
int k = 0;
while(s) {
nb_temperature_thresholds = 1;
- char *s;
+ char *s, *u;
+
s = definition;
while(s) {
s = next_word(token, s, buffer_size);
}
temperature_thresholds =
- (int *) malloc(nb_temperature_thresholds * sizeof(int));
+ safe_malloc(nb_temperature_thresholds * sizeof(int));
+
+ speed_names =
+ safe_malloc(nb_temperature_thresholds * sizeof(char *));
temperature_thresholds[0] = -1;
int k = 1;
while(s) {
s = next_word(token, s, buffer_size);
- temperature_thresholds[k] = atoi(token);
+ u = token;
+ while(*u && *u != ':') u++;
+ if(*u) {
+ *u = '\0';
+ temperature_thresholds[k] = atoi(token);
+ u++;
+ speed_names[k] = strdup(u);
+ } else {
+ temperature_thresholds[k] = atoi(token);
+ snprintf(token, buffer_size, "%d", k);
+ speed_names[k] = strdup(token);
+ }
+
if(k > 0 &&
temperature_thresholds[k] < temperature_thresholds[k-1]) {
fprintf(stderr, "The temperature thresholds have to be increasing.\n");
printf("file_fan %s\n", file_fan);
for(t = 0; t < nb_temperature_thresholds; t++) {
- printf("temperature_thresholds[%d] %d",
- t, temperature_thresholds[t]);
+ printf("temperature_thresholds[%d] = %d speed_names[%d] = \"%s\"\n",
+ t, temperature_thresholds[t],
+ t, speed_names[t]);
}
}
nb_rounds_since_last_change = 0;
last_level = new_level;
if(debug) {
- printf("Temperature is %dC setting the fan level to %d.",
+ printf("Temperature is %dC setting the fan level to %d.\n",
temperature, new_level);
}
}