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