-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbsdfan.c
91 lines (71 loc) · 1.5 KB
/
bsdfan.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <sys/param.h>
#include <sys/linker.h>
#include <err.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "common.h"
#include "parser.h"
#include "system.h"
#define INVALID_ARGUMENT_ERROR "Arugment not recognised"
#define MODULE_LOAD_ERROR "Module acpi_ibm.ko load failed"
#define DEFAULT_CONF_PATH LOCALBASE "/etc/bsdfan.conf"
#define VERSION "0.1"
static void
autofan(int sig __unused)
{
setFan(AUTO,NULL);
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[])
{
const char *confpath= DEFAULT_CONF_PATH;
char op;
bool daemonize = false;
const struct Config *conf;
if (kldfind("acpi_ibm")== -1)
if(kldload("acpi_ibm")==-1)
err(EXIT_FAILURE, MODULE_LOAD_ERROR);
while( (op = getopt(argc, argv, "vdc:")) != -1)
{
switch(op)
{
case 'v':
printf("Version: %s\n",VERSION);
exit(0);
break;
case 'd':
daemonize = true;
break;
case 'c':
confpath=optarg;
break;
case '?':
errx(EXIT_FAILURE, INVALID_ARGUMENT_ERROR);
break;
default:
break;
}
}
conf = readConfig(confpath);
/* when exit you must reset the fan to AUTO */
(void) signal (SIGINT, autofan);
(void) signal (SIGTERM, autofan);
(void) signal (SIGHUP, autofan);
(void) signal (SIGSEGV, autofan);
setFan(MANUAL,conf->levels);
int oldtemp=0;
if(daemonize)
daemon(0,0);
while(1)
{
int time =2;
int cur_temp = getTemp();
if(oldtemp-cur_temp>2)
time =1;
oldtemp = cur_temp;
adjustLevel(cur_temp,conf);
sleep(time);
}
}