| 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 "noit_listener.h" |
|---|
| 13 |
#include "noit_console.h" |
|---|
| 14 |
#include "noit_module.h" |
|---|
| 15 |
#include "noit_conf.h" |
|---|
| 16 |
|
|---|
| 17 |
static char *config_file = ETC_DIR "/noit.conf"; |
|---|
| 18 |
static int debug = 0; |
|---|
| 19 |
|
|---|
| 20 |
void parse_clargs(int argc, char **argv) { |
|---|
| 21 |
int c; |
|---|
| 22 |
while((c = getopt(argc, argv, "c:d")) != EOF) { |
|---|
| 23 |
switch(c) { |
|---|
| 24 |
case 'c': |
|---|
| 25 |
config_file = strdup(optarg); |
|---|
| 26 |
break; |
|---|
| 27 |
case 'd': |
|---|
| 28 |
debug++; |
|---|
| 29 |
break; |
|---|
| 30 |
default: |
|---|
| 31 |
break; |
|---|
| 32 |
} |
|---|
| 33 |
} |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
int main(int argc, char **argv) { |
|---|
| 37 |
char conf_str[1024]; |
|---|
| 38 |
parse_clargs(argc, argv); |
|---|
| 39 |
|
|---|
| 40 |
/* First initialize logging, so we can log errors */ |
|---|
| 41 |
noit_log_init(); |
|---|
| 42 |
if(debug) |
|---|
| 43 |
noit_log_stream_add_stream(noit_debug, noit_stderr); |
|---|
| 44 |
noit_log_stream_add_stream(noit_error, noit_stderr); |
|---|
| 45 |
|
|---|
| 46 |
/* Next load the configs */ |
|---|
| 47 |
noit_conf_init(); |
|---|
| 48 |
if(noit_conf_load(config_file) == -1) { |
|---|
| 49 |
fprintf(stderr, "Cannot load config: '%s'\n", config_file); |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
/* Lastly, run through all other system inits */ |
|---|
| 53 |
if(!noit_conf_get_stringbuf(NULL, "/global/eventer/implementation", |
|---|
| 54 |
conf_str, sizeof(conf_str))) { |
|---|
| 55 |
noit_log(noit_stderr, NULL, "Cannot find '%s' in configuration\n", |
|---|
| 56 |
"/global/eventer/implementation"); |
|---|
| 57 |
exit(-1); |
|---|
| 58 |
} |
|---|
| 59 |
if(eventer_choose(conf_str) == -1) { |
|---|
| 60 |
noit_log(noit_stderr, NULL, "Cannot choose eventer %s\n", conf_str); |
|---|
| 61 |
exit(-1); |
|---|
| 62 |
} |
|---|
| 63 |
if(eventer_init() == -1) { |
|---|
| 64 |
noit_log(noit_stderr, NULL, "Cannot init eventer %s\n", conf_str); |
|---|
| 65 |
exit(-1); |
|---|
| 66 |
} |
|---|
| 67 |
noit_console_init(); |
|---|
| 68 |
noit_module_init(); |
|---|
| 69 |
noit_listener_init(); |
|---|
| 70 |
|
|---|
| 71 |
eventer_loop(); |
|---|
| 72 |
return 0; |
|---|
| 73 |
} |
|---|