2323#include <unistd.h>
2424#include <syslog.h>
2525#include <stdbool.h>
26- #include <sys/types.h>
27- #include <dirent.h>
2826#include <errno.h>
2927#include "mbpfan.h"
3028#include "daemon.h"
3129#include "global.h"
32- #include "main.h"
33- #include "minunit.h"
3430#include "util.h"
3531
36- int daemonize = 1 ;
37- int verbose = 0 ;
38-
39- const char * PROGRAM_NAME = "mbpfan" ;
40- const char * PROGRAM_VERSION = "2.2.0" ;
41- const char * PROGRAM_PID = "/var/run/mbpfan.pid" ;
42-
43- const char * CORETEMP_PATH = "/sys/devices/platform/coretemp.0" ;
44- const char * APPLESMC_PATH = "/sys/devices/platform/applesmc.768" ;
45-
4632void print_usage (int argc , char * argv [])
4733{
4834 if (argc >=1 ) {
4935 printf ("Usage: %s OPTION(S) \n" , argv [0 ]);
5036 printf ("Options:\n" );
5137 printf ("\t-h Show this help screen\n" );
5238 printf ("\t-f Run in foreground\n" );
53- printf ("\t-t Run the tests\n" );
5439 printf ("\t-v Be (a lot) verbose\n" );
5540 printf ("\n" );
5641 }
5742}
5843
59- void check_requirements ()
60- {
61-
62- /**
63- * Check for root
64- */
65-
66- uid_t uid = getuid (), euid = geteuid ();
67-
68- if (uid != 0 || euid != 0 ) {
69- mbp_log (LOG_ERR , "%s needs root privileges. Please run %s as root. Exiting." , PROGRAM_NAME , PROGRAM_NAME );
70- exit (EXIT_FAILURE );
71- }
72-
73- /**
74- * Check for coretemp and applesmc modules
75- */
76- DIR * dir = opendir (CORETEMP_PATH );
77-
78- if (ENOENT == errno ) {
79- mbp_log (LOG_ERR , "%s needs coretemp support. Please either load it or build it into the kernel. Exiting." , PROGRAM_NAME );
80- exit (EXIT_FAILURE );
81- }
82-
83- closedir (dir );
84-
85-
86- dir = opendir (APPLESMC_PATH );
87-
88- if (ENOENT == errno ) {
89- mbp_log (LOG_ERR , "%s needs applesmc support. Please either load it or build it into the kernel. Exiting." , PROGRAM_NAME );
90- exit (EXIT_FAILURE );
91- }
92-
93- closedir (dir );
94-
95-
96- }
97-
9844int main (int argc , char * argv [])
9945{
10046
10147 int c ;
10248
103- while ( (c = getopt (argc , argv , "hftv |help" )) != -1 ) {
49+ while ( (c = getopt (argc , argv , "hfv |help" )) != -1 ) {
10450 switch (c ) {
10551 case 'h' :
10652 print_usage (argc , argv );
@@ -111,9 +57,6 @@ int main(int argc, char *argv[])
11157 daemonize = 0 ;
11258 break ;
11359
114- case 't' :
115- return tests ();
116-
11760 case 'v' :
11861 verbose = 1 ;
11962 break ;
@@ -125,7 +68,7 @@ int main(int argc, char *argv[])
12568 }
12669 }
12770
128- check_requirements ();
71+ check_requirements (argv [ 0 ] );
12972
13073 // pointer to mbpfan() function in mbpfan.c
13174 void (* fan_control )() = mbpfan ;
0 commit comments