2012-06-15 21:07:11 +02:00
|
|
|
/**
|
|
|
|
* Copyright (C) (2012) Daniel Graziotin <dgraziotin@task3.cc>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
2012-06-16 11:02:48 +02:00
|
|
|
|
2012-08-23 22:32:49 +02:00
|
|
|
/**
|
|
|
|
* Code formatted with astyle -A3 -s --break-blocks=all --add-brackets *.c *.h
|
|
|
|
*/
|
|
|
|
|
2012-06-11 21:43:53 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include "mbpfan.h"
|
|
|
|
#include "daemon.h"
|
|
|
|
#include "global.h"
|
2012-06-16 11:02:48 +02:00
|
|
|
#include "minunit.h"
|
2012-10-19 18:25:10 +02:00
|
|
|
#include <syslog.h>
|
2012-06-11 21:43:53 +02:00
|
|
|
|
|
|
|
int daemonize = 1;
|
|
|
|
int verbose = 0;
|
|
|
|
|
2012-06-15 21:07:11 +02:00
|
|
|
const char *program_name = "mbpfan";
|
|
|
|
const char *program_pid = "/var/run/mbpfan.pid";
|
|
|
|
|
2012-06-11 21:43:53 +02:00
|
|
|
void print_usage(int argc, char *argv[])
|
|
|
|
{
|
2012-08-22 15:05:52 +02:00
|
|
|
if (argc >=1) {
|
|
|
|
printf("Usage: %s OPTION(S) \n", argv[0]);
|
|
|
|
printf("Options:\n");
|
|
|
|
printf("\t-h Show this help screen\n");
|
|
|
|
printf("\t-f Run in foreground\n");
|
|
|
|
printf("\t-t Run the tests\n");
|
|
|
|
printf("\t-v Be (a lot) verbose\n");
|
|
|
|
printf("\n");
|
2012-06-16 11:02:48 +02:00
|
|
|
}
|
2012-06-11 21:43:53 +02:00
|
|
|
}
|
|
|
|
|
2012-06-16 11:02:48 +02:00
|
|
|
|
|
|
|
|
2012-06-11 21:43:53 +02:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
|
2012-08-22 15:05:52 +02:00
|
|
|
int c;
|
2012-08-23 22:32:49 +02:00
|
|
|
|
2012-08-22 15:05:52 +02:00
|
|
|
while( (c = getopt(argc, argv, "hftv|help")) != -1) {
|
|
|
|
switch(c) {
|
2012-06-16 11:02:48 +02:00
|
|
|
case 'h':
|
2012-08-22 15:05:52 +02:00
|
|
|
print_usage(argc, argv);
|
|
|
|
exit(0);
|
|
|
|
break;
|
2012-06-16 11:02:48 +02:00
|
|
|
case 'f':
|
2012-08-22 15:05:52 +02:00
|
|
|
daemonize = 0;
|
|
|
|
break;
|
2012-06-16 11:02:48 +02:00
|
|
|
case 't':
|
2012-08-22 15:05:52 +02:00
|
|
|
tests();
|
|
|
|
exit(0);
|
|
|
|
break;
|
2012-06-16 11:02:48 +02:00
|
|
|
case 'v':
|
2012-08-22 15:05:52 +02:00
|
|
|
verbose = 1;
|
|
|
|
break;
|
2012-06-16 11:02:48 +02:00
|
|
|
default:
|
2012-08-22 15:05:52 +02:00
|
|
|
print_usage(argc, argv);
|
|
|
|
exit(0);
|
|
|
|
break;
|
2012-06-11 21:43:53 +02:00
|
|
|
}
|
2012-06-16 11:02:48 +02:00
|
|
|
}
|
2012-06-11 21:43:53 +02:00
|
|
|
|
2012-10-19 18:25:10 +02:00
|
|
|
uid_t uid=getuid(), euid=geteuid();
|
|
|
|
if (!(uid<0 || uid!=euid)) {
|
|
|
|
syslog(LOG_INFO, "Mbpfan not started with root privileges. Exiting.");
|
|
|
|
printf("Mbpfan not started with root privileges. Exiting.\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:05:52 +02:00
|
|
|
// pointer to mbpfan() function in mbpfan.c
|
|
|
|
void (*fan_control)() = mbpfan;
|
|
|
|
go_daemon(fan_control);
|
|
|
|
exit(0);
|
2012-06-11 21:43:53 +02:00
|
|
|
}
|