1 |
#include "noit_defines.h" |
---|
2 |
|
---|
3 |
#include <stdio.h> |
---|
4 |
#include <stdlib.h> |
---|
5 |
#include <unistd.h> |
---|
6 |
#include <errno.h> |
---|
7 |
#include <sys/ioctl.h> |
---|
8 |
#include <fcntl.h> |
---|
9 |
|
---|
10 |
#include "eventer/eventer.h" |
---|
11 |
#include "utils/noit_log.h" |
---|
12 |
#include "utils/noit_hash.h" |
---|
13 |
#include "noit_listener.h" |
---|
14 |
#include "noit_console.h" |
---|
15 |
#include "noit_jlog_listener.h" |
---|
16 |
#include "noit_module.h" |
---|
17 |
#include "noit_conf.h" |
---|
18 |
#include "noit_conf_checks.h" |
---|
19 |
#include "noit_filters.h" |
---|
20 |
|
---|
21 |
#define APPNAME "noit" |
---|
22 |
|
---|
23 |
static char *config_file = ETC_DIR "/" APPNAME ".conf"; |
---|
24 |
static int debug = 0; |
---|
25 |
|
---|
26 |
void parse_clargs(int argc, char **argv) { |
---|
27 |
int c; |
---|
28 |
while((c = getopt(argc, argv, "c:d")) != EOF) { |
---|
29 |
switch(c) { |
---|
30 |
case 'c': |
---|
31 |
config_file = strdup(optarg); |
---|
32 |
break; |
---|
33 |
case 'd': |
---|
34 |
debug++; |
---|
35 |
break; |
---|
36 |
default: |
---|
37 |
break; |
---|
38 |
} |
---|
39 |
} |
---|
40 |
} |
---|
41 |
|
---|
42 |
static |
---|
43 |
int configure_eventer() { |
---|
44 |
int rv = 0; |
---|
45 |
noit_hash_table *table; |
---|
46 |
table = noit_conf_get_hash(NULL, "/" APPNAME "/eventer/config"); |
---|
47 |
if(table) { |
---|
48 |
noit_hash_iter iter = NOIT_HASH_ITER_ZERO; |
---|
49 |
const char *key, *value; |
---|
50 |
int klen; |
---|
51 |
while(noit_hash_next(table, &iter, &key, &klen, (void **)&value)) { |
---|
52 |
int subrv; |
---|
53 |
if((subrv = eventer_propset(key, value)) != 0) |
---|
54 |
rv = subrv; |
---|
55 |
} |
---|
56 |
noit_hash_destroy(table, free, free); |
---|
57 |
free(table); |
---|
58 |
} |
---|
59 |
return rv; |
---|
60 |
} |
---|
61 |
|
---|
62 |
int main(int argc, char **argv) { |
---|
63 |
char conf_str[1024]; |
---|
64 |
|
---|
65 |
parse_clargs(argc, argv); |
---|
66 |
|
---|
67 |
/* First initialize logging, so we can log errors */ |
---|
68 |
noit_log_init(); |
---|
69 |
noit_log_stream_add_stream(noit_debug, noit_stderr); |
---|
70 |
noit_log_stream_add_stream(noit_error, noit_stderr); |
---|
71 |
|
---|
72 |
/* Next load the configs */ |
---|
73 |
noit_conf_init(APPNAME); |
---|
74 |
noit_conf_checks_init(APPNAME); |
---|
75 |
if(noit_conf_load(config_file) == -1) { |
---|
76 |
fprintf(stderr, "Cannot load config: '%s'\n", config_file); |
---|
77 |
} |
---|
78 |
|
---|
79 |
/* Reinitialize the logging system now that we have a config */ |
---|
80 |
noit_conf_log_init(APPNAME); |
---|
81 |
if(debug) |
---|
82 |
noit_debug->enabled = 1; |
---|
83 |
|
---|
84 |
/* Lastly, run through all other system inits */ |
---|
85 |
if(!noit_conf_get_stringbuf(NULL, "/" APPNAME "/eventer/@implementation", |
---|
86 |
conf_str, sizeof(conf_str))) { |
---|
87 |
noitL(noit_stderr, "Cannot find '%s' in configuration\n", |
---|
88 |
"/" APPNAME "/eventer/@implementation"); |
---|
89 |
exit(-1); |
---|
90 |
} |
---|
91 |
if(eventer_choose(conf_str) == -1) { |
---|
92 |
noitL(noit_stderr, "Cannot choose eventer %s\n", conf_str); |
---|
93 |
exit(-1); |
---|
94 |
} |
---|
95 |
if(configure_eventer() != 0) { |
---|
96 |
noitL(noit_stderr, "Cannot configure eventer\n"); |
---|
97 |
exit(-1); |
---|
98 |
} |
---|
99 |
if(eventer_init() == -1) { |
---|
100 |
noitL(noit_stderr, "Cannot init eventer %s\n", conf_str); |
---|
101 |
exit(-1); |
---|
102 |
} |
---|
103 |
/* Initialize all of our listeners */ |
---|
104 |
noit_console_init(); |
---|
105 |
noit_jlog_listener_init(); |
---|
106 |
|
---|
107 |
noit_module_init(); |
---|
108 |
noit_filters_init(); |
---|
109 |
noit_poller_init(); |
---|
110 |
noit_listener_init(APPNAME); |
---|
111 |
|
---|
112 |
eventer_loop(); |
---|
113 |
return 0; |
---|
114 |
} |
---|