From fff4b50bb272e6825829290ca9814bd82453c46e Mon Sep 17 00:00:00 2001 From: "otilmans@gmail.com" Date: Mon, 21 Jul 2014 23:42:37 +0200 Subject: [PATCH 1/5] Remove redundant typedef's --- src/mbpfan.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/mbpfan.c b/src/mbpfan.c index f2706db..2090dda 100755 --- a/src/mbpfan.c +++ b/src/mbpfan.c @@ -59,8 +59,6 @@ int max_temp = 86; // do not set it > 90 int polling_interval = 7; -typedef struct s_sensors t_sensors; -typedef struct s_fans t_fans; bool is_legacy_kernel() { From f5f61ccf69dc6ce9d40347bd677f0ec544c124b1 Mon Sep 17 00:00:00 2001 From: "otilmans@gmail.com" Date: Mon, 21 Jul 2014 23:43:02 +0200 Subject: [PATCH 2/5] Fix unused variable --- src/mbpfan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mbpfan.c b/src/mbpfan.c index 2090dda..d31c3ad 100755 --- a/src/mbpfan.c +++ b/src/mbpfan.c @@ -241,7 +241,7 @@ t_fans *retrieve_fans() int counter = 0; int fans_found = 0; - for(int counter = 0; counter<10; counter++) { + for(counter = 0; counter<10; counter++) { path_output = (char*) malloc(sizeof( char ) * path_min_size); path_output[0] = '\0'; From 44d2ad7b821fb781aa24403bed90ad3acc13510b Mon Sep 17 00:00:00 2001 From: "otilmans@gmail.com" Date: Mon, 21 Jul 2014 23:43:39 +0200 Subject: [PATCH 3/5] Expose fans and sensors globally --- src/global.h | 2 ++ src/mbpfan.c | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/global.h b/src/global.h index 472bad3..9b64acf 100644 --- a/src/global.h +++ b/src/global.h @@ -23,5 +23,7 @@ struct s_fans { typedef struct s_sensors t_sensors; typedef struct s_fans t_fans; +extern t_sensors* sensors; +extern t_fans* fans; #endif \ No newline at end of file diff --git a/src/mbpfan.c b/src/mbpfan.c index d31c3ad..40524a2 100755 --- a/src/mbpfan.c +++ b/src/mbpfan.c @@ -59,6 +59,9 @@ int max_temp = 86; // do not set it > 90 int polling_interval = 7; +t_sensors* sensors = NULL; +t_fans* fans = NULL; + bool is_legacy_kernel() { @@ -486,8 +489,8 @@ void mbpfan() retrieve_settings(NULL); - t_sensors* sensors = retrieve_sensors(); - t_fans* fans = retrieve_fans(); + sensors = retrieve_sensors(); + fans = retrieve_fans(); set_fans_man(fans); new_temp = get_temp(sensors); From 8bb61f8633cdab31099fdd1f481597621a517822 Mon Sep 17 00:00:00 2001 From: "otilmans@gmail.com" Date: Mon, 21 Jul 2014 23:44:13 +0200 Subject: [PATCH 4/5] Add function to give back fan control to applesmc --- src/mbpfan.c | 16 ++++++++++++++-- src/mbpfan.h | 6 ++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/mbpfan.c b/src/mbpfan.c index 40524a2..5ddffb3 100755 --- a/src/mbpfan.c +++ b/src/mbpfan.c @@ -314,7 +314,7 @@ t_fans *retrieve_fans() } -void set_fans_man(t_fans *fans) +static void set_fans_mode(t_fans *fans, int mode) { t_fans *tmp = fans; @@ -324,7 +324,7 @@ void set_fans_man(t_fans *fans) file = fopen(tmp->fan_manual_path, "rw+"); if(file != NULL) { - fprintf(file, "%d", 1); + fprintf(file, "%d", mode); fclose(file); } @@ -332,6 +332,18 @@ void set_fans_man(t_fans *fans) } } +void set_fans_man(t_fans *fans) +{ + + set_fans_mode(fans, 1); +} + +void set_fans_auto(t_fans *fans) +{ + + set_fans_mode(fans, 0); +} + t_sensors *refresh_sensors(t_sensors *sensors) { diff --git a/src/mbpfan.h b/src/mbpfan.h index c9ed069..d6250fa 100644 --- a/src/mbpfan.h +++ b/src/mbpfan.h @@ -79,6 +79,12 @@ t_fans* retrieve_fans(); */ void set_fans_man(t_fans *fans); +/** + * Given a list of sensors with associated fans + * Set them to automatic control + */ +void set_fans_auto(t_fans *fans); + /** * Given a list of sensors with associated fans * Change their speed From 511d348adb9e1cb8ea6f90c7bb9dc1941b8ff2c0 Mon Sep 17 00:00:00 2001 From: "otilmans@gmail.com" Date: Mon, 21 Jul 2014 23:45:08 +0200 Subject: [PATCH 5/5] Handle back control to applesmc on exit --- src/daemon.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/daemon.c b/src/daemon.c index 8f110a9..07e3271 100755 --- a/src/daemon.c +++ b/src/daemon.c @@ -79,6 +79,7 @@ void signal_handler(int signal) syslog(LOG_WARNING, "Received SIGTERM signal."); delete_pid(); //TODO: free resources + set_fans_auto(fans); exit(EXIT_SUCCESS); break; @@ -86,12 +87,14 @@ void signal_handler(int signal) syslog(LOG_WARNING, "Received SIGINT signal."); delete_pid(); //TODO: free resources + set_fans_auto(fans); exit(EXIT_SUCCESS); case SIGSTOP: syslog(LOG_WARNING, "Received SIGSTOP signal."); delete_pid(); //TODO: free resources + set_fans_auto(fans); exit(EXIT_SUCCESS); default: