Merge branch 'reopen-fan' of git://github.com/andrewgaul/mbpfan into andrewgaul-reopen-fan

This commit is contained in:
Daniel Graziotin 2017-07-20 12:06:28 +02:00
commit b2cd98448f
3 changed files with 21 additions and 15 deletions

View file

@ -82,6 +82,9 @@ static void cleanup_and_exit(int exit_code)
struct s_fans *next_fan;
while (fans != NULL) {
next_fan = fans->next;
if (fans->file != NULL) {
fclose(fans->file);
}
free(fans->fan_output_path);
free(fans->fan_manual_path);
free(fans);
@ -91,6 +94,9 @@ static void cleanup_and_exit(int exit_code)
struct s_sensors *next_sensor;
while (sensors != NULL) {
next_sensor = sensors->next;
if (sensors->file != NULL) {
fclose(sensors->file);
}
free(sensors->path);
free(sensors);
sensors = next_sensor;

View file

@ -8,13 +8,15 @@ extern const char* PROGRAM_NAME;
extern const char* PROGRAM_PID;
struct s_sensors {
FILE* file;
char* path;
unsigned int temperature;
struct s_sensors *next;
};
struct s_fans {
char* path;
FILE* file;
char* path; // TODO: unused
char* fan_output_path;
char* fan_manual_path;
struct s_fans *next;

View file

@ -206,7 +206,7 @@ t_sensors *retrieve_sensors()
tmp->next->next = NULL;
}
fclose(file);
s->file = file;
sensors_found++;
}
@ -273,7 +273,7 @@ t_fans *retrieve_fans()
strncat( path_manual, path_man_end, strlen(path_begin) );
FILE *file = fopen(path_output, "r");
FILE *file = fopen(path_output, "w");
if(file != NULL) {
fan = (t_fans *) malloc( sizeof( t_fans ) );
@ -297,7 +297,7 @@ t_fans *retrieve_fans()
tmp->next->next = NULL;
}
fclose(file);
fan->file = file;
fans_found++;
}
@ -362,11 +362,11 @@ t_sensors *refresh_sensors(t_sensors *sensors)
t_sensors *tmp = sensors;
while(tmp != NULL) {
FILE *file = fopen(tmp->path, "r");
if(file != NULL) {
fscanf(file, "%d", &tmp->temperature);
fclose(file);
if(tmp->file != NULL) {
char buf[16];
int len = pread(fileno(tmp->file), buf, sizeof(buf), /*offset=*/ 0);
buf[len] = '\0';
sscanf(buf, "%d", &tmp->temperature);
}
tmp = tmp->next;
@ -380,14 +380,12 @@ t_sensors *refresh_sensors(t_sensors *sensors)
void set_fan_speed(t_fans* fans, int speed)
{
t_fans *tmp = fans;
FILE *file;
while(tmp != NULL) {
file = fopen(tmp->fan_output_path, "rw+");
if(file != NULL) {
fprintf(file, "%d", speed);
fclose(file);
if(tmp->file != NULL) {
char buf[16];
int len = snprintf(buf, sizeof(buf), "%d", speed);
pwrite(fileno(tmp->file), buf, len, /*offset=*/ 0);
}
tmp = tmp->next;