root/src/noitd.c

Revision 5f388ee20a06c319202cb070628c7bc827ffbb0a, 2.5 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 years ago)

split out the noit(check) specific conf stuff into its own file

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