Hallo,
basierend auf Husio's simple app in C
http://wiki.archlinux.org/index.php/Macbook#Fan_Speed
habe ich das Prog für den core duo umgeschrieben.
nano /etc/rc.d/cmp-daemond
#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
PID=`pidof -o %PPID /usr/sbin/cmp-daemond`
case "$1" in
start)
stat_busy "Starting Cool-Macbook-Pro-Daemon"
if [ -z "$PID" ]; then
/usr/sbin/cmp-daemond -d
fi
if [ ! -z "$PID" -o $? -gt 0 ]; then
stat_fail
else
add_daemon cmp-daemond
stat_done
fi
;;
stop)
stat_busy "Stopping Cool-Macbook-Pro-Daemon"
[ ! -z "$PID" ] && kill $PID &> /dev/null
if [ $? -gt 0 ]; then
stat_fail
else
rm_daemon cmp-daemond
stat_done
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
;;
esac
exit 0
----
nano /usr/sbin/cmp-daemond.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <time.h>
#include <signal.h>
#include <string.h>
#define LOGFILE "/var/log/daemon.log"
#define PIDFILE "/var/run/cmp-daemond.pid"
#define FAN_1_MANUAL "/sys/devices/platform/applesmc.768/fan1_manual"
#define FAN_2_MANUAL "/sys/devices/platform/applesmc.768/fan2_manual"
#define RD_FAN_SPEED_1 "/sys/devices/platform/applesmc.768/fan1_input"
#define RD_FAN_SPEED_2 "/sys/devices/platform/applesmc.768/fan2_input"
#define RD_CPU_TEMP_1 "/sys/devices/platform/coretemp.0/temp1_input"
#define RD_CPU_TEMP_2 "/sys/devices/platform/coretemp.1/temp1_input"
#define WR_FAN_SPEED_1 "/sys/devices/platform/applesmc.768/fan1_output"
#define WR_FAN_SPEED_2 "/sys/devices/platform/applesmc.768/fan2_output"
#define MIN_SPEED 2200
#define MAX_SPEED 6000
#define ERROR -1
#define OK 0
int write_pidfile(void);
int check_pidfile(void);
int write_fan_manual_1(int);
int write_fan_manual_2(int);
int read_cpu_temp_1(void);
int read_cpu_temp_2(void);
void write_fan_speed_1(int);
void write_fan_speed_2(int);
void log_message(char*);
void Signal_Handler(int sig){
switch(sig){
case SIGHUP:
break;
case SIGTERM:
write_fan_manual_1(0);
write_fan_manual_2(0);
unlink(PIDFILE);
log_message("Stop\n");
exit(OK);
break;
}
}
void start_daemon(void){
int i;
int erg;
pid_t pid;
pid=fork();
if (pid<0){
/* fork error */
log_message("Error fork\n");
exit(ERROR);
}
if (pid>0){
erg=check_pidfile();
if (erg!=ERROR){
erg=write_pidfile();
}
if (erg!=ERROR) {
erg=write_fan_manual_1(1);
}
if (erg!=ERROR){
erg=write_fan_manual_2(1);
}
exit(erg);
/* child (daemon) continues */
}
if(setsid() == ERROR){
log_message("Error setsid\n");
exit(ERROR);
}
for (i=getdtablesize();i>=0;--i) close(i);
umask(027);
chdir ("/");
}
int main(int argc, char **argv){
signal(SIGHUP,Signal_Handler); /* hangup signal */
signal(SIGTERM,Signal_Handler); /* software termination signal from kill */
struct timespec tim, tim2;
start_daemon();
tim.tv_sec = 0;
tim.tv_nsec = 700000000; // 0,7s
int i=0;
int rd_cpu_temp_1;
int rd_cpu_temp_2;
int add_fan_speed;
int old_temp=0;
log_message("Start\n");
while(1) {
rd_cpu_temp_1 = read_cpu_temp_1();
rd_cpu_temp_2 = read_cpu_temp_2();
i++;
if (i==10){
write_fan_manual_1(1);
write_fan_manual_2(1);
i=0;
}
if ( rd_cpu_temp_1 > 69000 ){
write_fan_speed_1(MAX_SPEED);
}
if ( rd_cpu_temp_2 > 69000 ) {
write_fan_speed_2(MAX_SPEED);
}
else {
if (rd_cpu_temp_1<50000){
rd_cpu_temp_1=50000;
}
if (rd_cpu_temp_2<50000){
rd_cpu_temp_2=50000;
}
add_fan_speed=((rd_cpu_temp_1 + rd_cpu_temp_2) - 99999)/10;
if (((rd_cpu_temp_1+rd_cpu_temp_2)>(old_temp+2600))||((rd_cpu_temp_1+rd_cpu_temp_2)<(old_temp-2600))){
write_fan_speed_1(MIN_SPEED + add_fan_speed);
write_fan_speed_2(MIN_SPEED + add_fan_speed);
old_temp=rd_cpu_temp_1+rd_cpu_temp_2;
}
}
if ( nanosleep(&tim, &tim2) < OK ) {
exit(ERROR);
}
}
}
int read_cpu_temp_1(void){
int temp;
FILE *file;
if ((file=fopen(RD_CPU_TEMP_1, "r"))==NULL){
log_message("Error read_cpu_temp_1\n");
unlink(PIDFILE);
exit(ERROR);
}
else {
fscanf(file,"%d",&temp);
fclose(file);
return temp;
}
}
int read_cpu_temp_2(void){
int temp;
FILE *file;
if ((file=fopen(RD_CPU_TEMP_2, "r"))==NULL){
log_message("Error read_cpu_temp_2\n");
unlink(PIDFILE);
exit(ERROR);
}
else {
fscanf(file,"%d", &temp);
fclose(file);
return temp;
}
}
void write_fan_speed_1(int speed){
FILE *file;
if((file=fopen(WR_FAN_SPEED_1, "w"))==NULL){
log_message("Error write_fan_speed_1, applesmc loaded?\n");
unlink(PIDFILE);
exit(ERROR);
}
else{
if (speed<MIN_SPEED) speed=MIN_SPEED;
if (speed>MAX_SPEED) speed=MAX_SPEED;
fprintf(file,"%d",speed);
fclose(file);
}
}
void write_fan_speed_2(int speed){
FILE *file;
if((file=fopen(WR_FAN_SPEED_2, "w"))==NULL){
log_message("Error write_fan_speed_2, applesmc loaded?\n");
unlink(PIDFILE);
exit(ERROR);
}
else{
if (speed<MIN_SPEED) speed=MIN_SPEED;
if (speed>MAX_SPEED) speed=MAX_SPEED;
fprintf(file,"%d",speed);
fclose(file);
}
}
int write_fan_manual_1(int manual_1){
FILE *file;
if((file=fopen(FAN_1_MANUAL, "w"))==NULL){
log_message("Error write_fan_manual_1, applesmc loaded?\n");
unlink(PIDFILE);
return ERROR;
}
else{
fprintf(file,"%d",manual_1);
fclose(file);
return OK;
}
}
int write_fan_manual_2(int manual_2){
FILE *file;
if((file=fopen(FAN_2_MANUAL, "w"))==NULL){
log_message("Error write_fan_manual_2, applesmc loaded?\n");
unlink(PIDFILE);
return ERROR;
}
else{
fprintf(file,"%d",manual_2);
fclose(file);
return OK;
}
}
int write_pidfile(){
FILE *file;
if((file=fopen(PIDFILE, "w"))==NULL){
log_message("Error write_pidfile\n");
unlink(PIDFILE);
return ERROR;
}
else{
fprintf(file,"%d",getpid());
fclose(file);
return OK;
}
}
int check_pidfile(){
FILE *file;
if((file=fopen(PIDFILE,"r"))!=NULL){
log_message("Error check_pidfile\n");
fclose(file);
return ERROR;
}
else{
return OK;
}
}
void log_message(char *message){
time_t t;
char *mytime;
time(&t);
mytime=ctime(&t);
mytime [ strlen( mytime ) - 1 ] = 0x0;
FILE *file;
if((file=fopen(LOGFILE,"a"))==NULL){
unlink(PIDFILE);
exit(ERROR);
}
else{
fprintf(file,"%s cmp-daemond %s",mytime,message);
fclose(file);
}
}
/* EOF */
gcc -Wall cmp-daemond.c -o /usr/sbin/cmp-daemond
Grüße Tribaltrouble