Skip to content

Commit 623f44d

Browse files
committed
Reformat source code with clang-tidy
Run with: clang-format -i src/* Closes #233.
1 parent 16f28f9 commit 623f44d

File tree

12 files changed

+255
-273
lines changed

12 files changed

+255
-273
lines changed

src/daemon.c

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
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

8280
static 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

114112
void 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
}

src/daemon.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,4 @@ void signal_handler(int signal);
5050
*/
5151
void go_daemon(void (*function)());
5252

53-
5453
#endif

src/global.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ extern int daemonize;
99
extern int verbose;
1010

1111
struct s_sensors {
12-
FILE* file;
13-
char* path;
12+
FILE *file;
13+
char *path;
1414
unsigned int temperature;
1515
struct s_sensors *next;
1616
};
1717

1818
struct s_fans {
19-
FILE* file;
20-
char* path; // TODO: unused
21-
char* label;
22-
char* fan_output_path;
23-
char* fan_manual_path;
19+
FILE *file;
20+
char *path; // TODO: unused
21+
char *label;
22+
char *fan_output_path;
23+
char *fan_manual_path;
2424
int step_up;
2525
int step_down;
2626
int fan_id;
@@ -33,7 +33,7 @@ struct s_fans {
3333
typedef struct s_sensors t_sensors;
3434
typedef struct s_fans t_fans;
3535

36-
extern t_sensors* sensors;
37-
extern t_fans* fans;
36+
extern t_sensors *sensors;
37+
extern t_fans *fans;
3838

3939
#endif

src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
void print_usage(int argc, char *argv[])
3333
{
34-
if (argc >=1) {
34+
if (argc >= 1) {
3535
printf("Usage: %s OPTION(S) \n", argv[0]);
3636
printf("Options:\n");
3737
printf("\t-h Show this help screen\n");
@@ -46,8 +46,8 @@ int main(int argc, char *argv[])
4646

4747
int c;
4848

49-
while( (c = getopt(argc, argv, "hfv|help")) != -1) {
50-
switch(c) {
49+
while ((c = getopt(argc, argv, "hfv|help")) != -1) {
50+
switch (c) {
5151
case 'h':
5252
print_usage(argc, argv);
5353
exit(EXIT_SUCCESS);

0 commit comments

Comments
 (0)