]> git.saurik.com Git - apple/system_cmds.git/blob - kextd.tproj/KEXTD_main.c
system_cmds-196.tar.gz
[apple/system_cmds.git] / kextd.tproj / KEXTD_main.c
1 #include <unistd.h>
2 #include <CoreFoundation/CoreFoundation.h>
3 #include "KEXTD.h"
4
5 #define TIMER_PERIOD_S 10
6 #define DEFAULT_SEARCH_PATH "/System/Library/Extensions/"
7
8 static const char * arg0 = NULL;
9
10 static void usage(void)
11 {
12 printf("usage: %s [-v] [-d] [-x] [-j] [-b bootlevel] [-f dirpath]\n", arg0);
13 exit(1);
14 }
15
16 int main (int argc, const char *argv[])
17 {
18 KEXTDRef kextd;
19 KEXTReturn error;
20 KEXTBootlevel bootlevel;
21 CFStringRef str;
22 CFURLRef url;
23 CFMutableArrayRef array;
24 CFIndex period;
25 Boolean safeBoot;
26 Boolean beVerbose;
27 Boolean enableTimer;
28 Boolean debug;
29 Boolean cdMKextBoot;
30 int c;
31
32 arg0 = argv[0];
33 period = TIMER_PERIOD_S;
34 debug = false;
35 safeBoot = false;
36 beVerbose = false;
37 enableTimer = false;
38 cdMKextBoot = false;
39 bootlevel = kKEXTBootlevelNormal;
40
41 url = CFURLCreateWithFileSystemPath(NULL, CFSTR(DEFAULT_SEARCH_PATH), kCFURLPOSIXPathStyle, true);
42 if ( !url ) {
43 printf("Error opening: %s.\n", DEFAULT_SEARCH_PATH);
44 exit(1);
45 }
46 array = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
47 CFArrayAppendValue(array, url);
48 CFRelease(url);
49
50 while ( (c = getopt(argc, (char **)argv, "xvdjb:f:")) != -1 ) {
51 switch ( c ) {
52
53 case 'x':
54 safeBoot = true;
55 break;
56 case 'v':
57 beVerbose = true;
58 break;
59 case 'd':
60 debug = true;
61 break;
62 #if TIMERSOURCE
63 case 'p':
64 if ( !optarg ) {
65 usage();
66 }
67 else {
68 period = strtoul(optarg, NULL, 0);
69 if ( period > 0 )
70 enableTimer = true;
71 }
72 break;
73 #endif
74
75 case 'b':
76 if ( !optarg ) {
77 usage();
78 }
79 bootlevel = strtoul(optarg, NULL, 0);
80 if ( bootlevel > 0x1f ) {
81 usage();
82 }
83 break;
84
85 case 'j':
86 cdMKextBoot = true;
87 break;
88
89 case 'f':
90 if ( !optarg ) {
91 usage();
92 }
93 str = CFStringCreateWithCString(NULL, optarg, kCFStringEncodingNonLossyASCII);
94 if ( str )
95 url = CFURLCreateWithFileSystemPath(NULL, str, kCFURLPOSIXPathStyle, true);
96 else
97 url = NULL;
98 if ( !url ) {
99 printf("Error opening: %s.\n", optarg);
100 } else {
101 CFArrayAppendValue(array, url);
102 CFRelease(url);
103 }
104 break;
105
106 default:
107 usage();
108 }
109 }
110 argc -= optind;
111 argv += optind;
112
113 if (argc != 0) {
114 usage();
115 }
116
117 kextd = KEXTDCreate(array, &error);
118 CFRelease(array);
119 if ( !kextd ) {
120 KEXTError(error, CFSTR("Error creating kextd"));
121 exit(error);
122 }
123
124 KEXTDRegisterHelperCallbacks(kextd, NULL);
125 #if TIMERSOURCE
126 error = KEXTDStartMain(kextd, beVerbose, safeBoot, debug, enableTimer, period, bootlevel, cdMKextBoot);
127 #else
128 error = KEXTDStartMain(kextd, beVerbose, safeBoot, debug, bootlevel, cdMKextBoot);
129 #endif
130 if ( error != kKEXTReturnSuccess ) {
131 KEXTDFree(kextd);
132 KEXTError(error, CFSTR("Error starting kextd"));
133 exit(error);
134 }
135 KEXTDFree(kextd);
136
137 return error;
138 }