Added support for configfile /etc/mbpfan.conf
This commit is contained in:
parent
1b84085a81
commit
6ea021ad78
5 changed files with 95 additions and 13 deletions
2
AUTHORS
2
AUTHORS
|
@ -2,7 +2,7 @@ MAINTAINERS AND CONTRIBUTORS
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
Daniel Graziotin <dgraziotin AT task3 DOT cc>
|
Daniel Graziotin <dgraziotin AT task3 DOT cc>
|
||||||
CeRiAl <ikhatib AT imail DOT de>
|
Ismail Khatib <ikhatib AT gmail DOT com>
|
||||||
|
|
||||||
|
|
||||||
ORIGINARY AUTHORS
|
ORIGINARY AUTHORS
|
||||||
|
|
22
Makefile
22
Makefile
|
@ -5,6 +5,7 @@ C = c
|
||||||
OUTPUT_PATH = bin/
|
OUTPUT_PATH = bin/
|
||||||
SOURCE_PATH = src/
|
SOURCE_PATH = src/
|
||||||
EXE = bin/mbpfan
|
EXE = bin/mbpfan
|
||||||
|
CONF = mbpfan.conf
|
||||||
|
|
||||||
ifeq ($(COMPILER), G++)
|
ifeq ($(COMPILER), G++)
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
|
@ -55,12 +56,29 @@ clean:
|
||||||
|
|
||||||
install:
|
install:
|
||||||
cp $(EXE) /usr/sbin
|
cp $(EXE) /usr/sbin
|
||||||
|
cp -n $(CONF) /etc
|
||||||
@echo "-----------------------------------------------------------------------------"
|
@echo "-----------------------------------------------------------------------------"
|
||||||
@echo "An init file suitable for /lib/lsb/init-functions (Debian & Ubuntu fur sure)"
|
@echo "An init file suitable for /lib/lsb/init-functions (Debian & Ubuntu for sure)"
|
||||||
@echo "Is located in the main folder of the source files. It is called mbpfan.init."
|
@echo "is located in the main folder of the source files, called mbpfan.init.debian"
|
||||||
@echo "Rename it to mbpfan, give it execution permissions (chmod +x mbpfan)"
|
@echo "Rename it to mbpfan, give it execution permissions (chmod +x mbpfan)"
|
||||||
@echo "and move it to /etc/init.d"
|
@echo "and move it to /etc/init.d"
|
||||||
@echo "Then, add it to the default runlevels with sudo update-rc.d mbpfan defaults"
|
@echo "Then, add it to the default runlevels with sudo update-rc.d mbpfan defaults"
|
||||||
|
@echo ""
|
||||||
|
@echo "Additionally, an init file suitable for /etc/rc.d/init.d/functions"
|
||||||
|
@echo "(RHEL/CentOS & Fedora) is also located at the same place, this file is called"
|
||||||
|
@echo "mbpfan.init.redhat. Also rename it to mbpfan, give it execution permissions"
|
||||||
|
@echo "and move it to /etc/init.d"
|
||||||
|
@echo "To add the script to the default runlevels, run the following as root:"
|
||||||
|
@echo "chkconfig --level 2345 mbpfan on && chkconfig --level 016 mbpfan off"
|
||||||
|
@echo ""
|
||||||
|
@echo "As a special bonus, a service file for systemd is also included. To use it,"
|
||||||
|
@echo "execute the following as root:"
|
||||||
|
@echo "cp mbpfan.service /usr/lib/systemd/system"
|
||||||
|
@echo "ln -s /usr/lib/systemd/system/mbpfan.service /etc/systemd/system/mbpfan.service"
|
||||||
|
@echo "systemctl daemon-reload"
|
||||||
|
@echo "systemctl start mbpfan.service"
|
||||||
|
@echo "To start the service automatically at boot, also execute the following:"
|
||||||
|
@echo "systemctl enable mbpfan.service"
|
||||||
@echo "-----------------------------------------------------------------------------"
|
@echo "-----------------------------------------------------------------------------"
|
||||||
|
|
||||||
rebuild: clean all
|
rebuild: clean all
|
||||||
|
|
7
mbpfan.conf
Normal file
7
mbpfan.conf
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
[general]
|
||||||
|
min_fan_speed = 2000 # default is 2000
|
||||||
|
max_fan_speed = 6200 # default is 6200
|
||||||
|
low_temp = 63 # try ranges 55-63, default is 63
|
||||||
|
high_temp = 66 # try ranges 58-66, default is 66
|
||||||
|
max_temp = 86 # do not set it > 90, default is 86
|
||||||
|
polling_interval = 7 # default is 7
|
|
@ -1,6 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (C) 2012 Peter Lombardo <http://peterlombardo.wikidot.com/linux-daemon-in-c>
|
* Copyright (C) 2012 Peter Lombardo <http://peterlombardo.wikidot.com/linux-daemon-in-c>
|
||||||
* Modifications (2012) by Daniel Graziotin <dgraziotin@task3.cc>
|
* Modifications (2012) by Daniel Graziotin <dgraziotin@task3.cc>
|
||||||
|
* Modifications (2012) by Ismail Khatib <ikhatib@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -162,7 +163,7 @@ void go_daemon(void (*fan_control)())
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
printf("Writing a new .pid file with value %d at: %s", current_pid, program_pid);
|
printf("Writing a new .pid file with value %d at: %s\n", current_pid, program_pid);
|
||||||
syslog(LOG_INFO, "Writing a new .pid file with value %d at: %s", current_pid, program_pid);
|
syslog(LOG_INFO, "Writing a new .pid file with value %d at: %s", current_pid, program_pid);
|
||||||
}
|
}
|
||||||
if (write_pid(current_pid) == 0)
|
if (write_pid(current_pid) == 0)
|
||||||
|
@ -170,7 +171,7 @@ void go_daemon(void (*fan_control)())
|
||||||
syslog(LOG_ERR, "Can not create a .pid file at: %s. Aborting", program_pid);
|
syslog(LOG_ERR, "Can not create a .pid file at: %s. Aborting", program_pid);
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
printf("ERROR: Can not create a .pid file at: %s. Aborting", program_pid);
|
printf("ERROR: Can not create a .pid file at: %s. Aborting\n", program_pid);
|
||||||
}
|
}
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
@ -178,7 +179,7 @@ void go_daemon(void (*fan_control)())
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
printf("Successfully written a new .pid file with value %d at: %s", current_pid, program_pid);
|
printf("Successfully written a new .pid file with value %d at: %s\n", current_pid, program_pid);
|
||||||
syslog(LOG_INFO, "Successfully written a new .pid file with value %d at: %s", current_pid, program_pid);
|
syslog(LOG_INFO, "Successfully written a new .pid file with value %d at: %s", current_pid, program_pid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
64
src/mbpfan.c
64
src/mbpfan.c
|
@ -3,6 +3,7 @@
|
||||||
* Copyright (C) 2010 Allan McRae <allan@archlinux.org>
|
* Copyright (C) 2010 Allan McRae <allan@archlinux.org>
|
||||||
* Modifications by Rafael Vega <rvega@elsoftwarehamuerto.org>
|
* Modifications by Rafael Vega <rvega@elsoftwarehamuerto.org>
|
||||||
* Modifications (2012) by Daniel Graziotin <dgraziotin@task3.cc>
|
* Modifications (2012) by Daniel Graziotin <dgraziotin@task3.cc>
|
||||||
|
* Modifications (2012) by Ismail Khatib <ikhatib@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -24,7 +25,8 @@
|
||||||
*
|
*
|
||||||
* Tested models:
|
* Tested models:
|
||||||
* MacBook Pro 8.1 13" (Intel i7 - Linux 3.2)
|
* MacBook Pro 8.1 13" (Intel i7 - Linux 3.2)
|
||||||
* Macbook Pro 6,2 15" (Intel i7 - Linux 3.2)
|
* MacBook Pro 6,2 15" (Intel i7 - Linux 3.2)
|
||||||
|
* MacBook Pro 2,2 15" (Intel Core 2 Duo - Linux 3.4.4)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,6 +38,7 @@
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include "mbpfan.h"
|
#include "mbpfan.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
/* lazy min/max... */
|
/* lazy min/max... */
|
||||||
#define min(a,b) a < b ? a : b
|
#define min(a,b) a < b ? a : b
|
||||||
|
@ -273,6 +276,9 @@ void mbpfan()
|
||||||
int old_temp, new_temp, fan_speed, steps;
|
int old_temp, new_temp, fan_speed, steps;
|
||||||
int temp_change;
|
int temp_change;
|
||||||
int step_up, step_down;
|
int step_up, step_down;
|
||||||
|
FILE *f = NULL;
|
||||||
|
Settings *settings = NULL;
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
t_sensors* sensors = retrieve_sensors();
|
t_sensors* sensors = retrieve_sensors();
|
||||||
set_fans_man(sensors);
|
set_fans_man(sensors);
|
||||||
|
@ -280,12 +286,62 @@ void mbpfan()
|
||||||
fan_speed = 2000;
|
fan_speed = 2000;
|
||||||
set_fan_speed(sensors, fan_speed);
|
set_fan_speed(sensors, fan_speed);
|
||||||
|
|
||||||
|
f = fopen("/etc/mbpfan.conf", "r");
|
||||||
|
if (f == NULL)
|
||||||
|
{
|
||||||
|
/* Could not open configfile */
|
||||||
|
if(verbose)
|
||||||
|
{
|
||||||
|
printf("Couldn't open configfile, using defaults\n");
|
||||||
|
if(daemonize)
|
||||||
|
{
|
||||||
|
syslog(LOG_INFO, "Couldn't open configfile, using defaults");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
settings = settings_open(f);
|
||||||
|
fclose(f);
|
||||||
|
if (settings == NULL)
|
||||||
|
{
|
||||||
|
/* Could not read configfile */
|
||||||
|
if(verbose)
|
||||||
|
{
|
||||||
|
printf("Couldn't read configfile\n");
|
||||||
|
if(daemonize)
|
||||||
|
{
|
||||||
|
syslog(LOG_INFO, "Couldn't read configfile");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Read configfile values */
|
||||||
|
result = settings_get_int(settings, "general", "min_fan_speed");
|
||||||
|
if (result != 0) min_fan_speed = result;
|
||||||
|
result = settings_get_int(settings, "general", "max_fan_speed");
|
||||||
|
if (result != 0) max_fan_speed = result;
|
||||||
|
result = settings_get_int(settings, "general", "low_temp");
|
||||||
|
if (result != 0) low_temp = result;
|
||||||
|
result = settings_get_int(settings, "general", "high_temp");
|
||||||
|
if (result != 0) high_temp = result;
|
||||||
|
result = settings_get_int(settings, "general", "max_temp");
|
||||||
|
if (result != 0) max_temp = result;
|
||||||
|
result = settings_get_int(settings, "general", "polling_interval");
|
||||||
|
if (result != 0) polling_interval = result;
|
||||||
|
|
||||||
|
/* Destroy the settings object */
|
||||||
|
settings_delete(settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(verbose)
|
if(verbose)
|
||||||
{
|
{
|
||||||
printf("Sleeping for %d seconds\n", polling_interval);
|
printf("Sleeping for %d seconds\n", polling_interval);
|
||||||
if(daemonize)
|
if(daemonize)
|
||||||
{
|
{
|
||||||
syslog(LOG_INFO, "Sleeping for %d seconds\n", polling_interval);
|
syslog(LOG_INFO, "Sleeping for %d seconds", polling_interval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sleep(polling_interval);
|
sleep(polling_interval);
|
||||||
|
@ -330,7 +386,7 @@ void mbpfan()
|
||||||
printf("Old Temp %d: New Temp: %d, Fan Speed: %d\n", old_temp, new_temp, fan_speed);
|
printf("Old Temp %d: New Temp: %d, Fan Speed: %d\n", old_temp, new_temp, fan_speed);
|
||||||
if(daemonize)
|
if(daemonize)
|
||||||
{
|
{
|
||||||
syslog(LOG_INFO, "Old Temp %d: New Temp: %d, Fan Speed: %d\n", old_temp, new_temp, fan_speed);
|
syslog(LOG_INFO, "Old Temp %d: New Temp: %d, Fan Speed: %d", old_temp, new_temp, fan_speed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,7 +397,7 @@ void mbpfan()
|
||||||
printf("Sleeping for %d seconds\n", polling_interval);
|
printf("Sleeping for %d seconds\n", polling_interval);
|
||||||
if(daemonize)
|
if(daemonize)
|
||||||
{
|
{
|
||||||
syslog(LOG_INFO, "Sleeping for %d seconds\n", polling_interval);
|
syslog(LOG_INFO, "Sleeping for %d seconds", polling_interval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sleep(polling_interval);
|
sleep(polling_interval);
|
||||||
|
|
Loading…
Add table
Reference in a new issue