1616 *
1717 */
1818
19-
2019#include <sys/prctl.h>
2120#include <sys/types.h>
2221#include <sys/stat.h>
@@ -43,7 +42,7 @@ int write_pid(int pid)
4342 FILE * file = NULL ;
4443 file = fopen (PROGRAM_PID , "w" );
4544
46- if (file != NULL ) {
45+ if (file != NULL ) {
4746 fprintf (file , "%d" , pid );
4847 fclose (file );
4948 return 1 ;
@@ -59,14 +58,13 @@ int read_pid()
5958 int pid = -1 ;
6059 file = fopen (PROGRAM_PID , "r" );
6160
62- if (file != NULL ) {
61+ if (file != NULL ) {
6362 fscanf (file , "%d" , & pid );
6463 fclose (file );
65- if (kill (pid , 0 ) == -1 && errno == ESRCH )
66- { /* a process with such a pid does not exist, remove the pid file */
67- if (remove (PROGRAM_PID ) == 0 ) {
68- return -1 ;
69- }
64+ if (kill (pid , 0 ) == -1 && errno == ESRCH ) { /* a process with such a pid does not exist, remove the pid file */
65+ if (remove (PROGRAM_PID ) == 0 ) {
66+ return -1 ;
67+ }
7068 }
7169 return pid ;
7270 }
@@ -81,40 +79,40 @@ int delete_pid()
8179
8280static void cleanup_and_exit (int exit_code )
8381{
84- delete_pid ();
85- set_fans_auto (fans );
86-
87- struct s_fans * next_fan ;
88- while (fans != NULL ) {
89- next_fan = fans -> next ;
90- if (fans -> file != NULL ) {
91- fclose (fans -> file );
92- }
93- free (fans -> label );
94- free (fans -> fan_output_path );
95- free (fans -> fan_manual_path );
96- free (fans );
97- fans = next_fan ;
98- }
99-
100- struct s_sensors * next_sensor ;
101- while (sensors != NULL ) {
102- next_sensor = sensors -> next ;
103- if (sensors -> file != NULL ) {
104- fclose (sensors -> file );
105- }
106- free (sensors -> path );
107- free (sensors );
108- sensors = next_sensor ;
109- }
110-
111- exit (exit_code );
82+ delete_pid ();
83+ set_fans_auto (fans );
84+
85+ struct s_fans * next_fan ;
86+ while (fans != NULL ) {
87+ next_fan = fans -> next ;
88+ if (fans -> file != NULL ) {
89+ fclose (fans -> file );
90+ }
91+ free (fans -> label );
92+ free (fans -> fan_output_path );
93+ free (fans -> fan_manual_path );
94+ free (fans );
95+ fans = next_fan ;
96+ }
97+
98+ struct s_sensors * next_sensor ;
99+ while (sensors != NULL ) {
100+ next_sensor = sensors -> next ;
101+ if (sensors -> file != NULL ) {
102+ fclose (sensors -> file );
103+ }
104+ free (sensors -> path );
105+ free (sensors );
106+ sensors = next_sensor ;
107+ }
108+
109+ exit (exit_code );
112110}
113111
114112void signal_handler (int signal )
115113{
116114
117- switch (signal ) {
115+ switch (signal ) {
118116 case SIGHUP :
119117 syslog (LOG_WARNING , "Received SIGHUP signal." );
120118 retrieve_settings (NULL , fans );
@@ -151,7 +149,7 @@ void go_daemon(void (*fan_control)())
151149 signal (SIGINT , signal_handler );
152150
153151 // Setup syslog logging - see SETLOGMASK(3)
154- if (verbose ) {
152+ if (verbose ) {
155153 setlogmask (LOG_UPTO (LOG_DEBUG ));
156154 openlog (PROGRAM_NAME , LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID , LOG_USER );
157155
@@ -198,15 +196,12 @@ void go_daemon(void (*fan_control)())
198196 exit (EXIT_FAILURE );
199197 }
200198
201-
202-
203199 /* Close out the standard file descriptors */
204200 close (STDIN_FILENO );
205201 close (STDOUT_FILENO );
206202 close (STDERR_FILENO );
207203 }
208204
209-
210205 int current_pid = getpid ();
211206
212207 if (read_pid () == -1 ) {
@@ -229,10 +224,9 @@ void go_daemon(void (*fan_control)())
229224 exit (EXIT_FAILURE );
230225 }
231226
232-
233227 fan_control ();
234228
235- if (daemonize ) {
229+ if (daemonize ) {
236230 syslog (LOG_INFO , "%s daemon exiting" , PROGRAM_NAME );
237231 }
238232}
0 commit comments