root/src/stratcond.c

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

jlog pulling

  • 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 "stratcon_jlog_streamer.h"
18
19 #define APPNAME "stratcon"
20 static char *config_file = ETC_DIR "/" APPNAME ".conf";
21 static int debug = 0;
22
23 void parse_clargs(int argc, char **argv) {
24   int c;
25   while((c = getopt(argc, argv, "c:d")) != EOF) {
26     switch(c) {
27       case 'c':
28         config_file = strdup(optarg);
29         break;
30       case 'd':
31         debug++;
32         break;
33       default:
34         break;
35     }
36   }
37 }
38
39 static
40 int configure_eventer() {
41   int rv = 0;
42   noit_hash_table *table;
43   table = noit_conf_get_hash(NULL, "/" APPNAME "/eventer/config");
44   if(table) {
45     noit_hash_iter iter = NOIT_HASH_ITER_ZERO;
46     const char *key, *value;
47     int klen;
48     while(noit_hash_next(table, &iter, &key, &klen, (void **)&value)) {
49       int subrv;
50       if((subrv = eventer_propset(key, value)) != 0)
51         rv = subrv;
52     }
53     noit_hash_destroy(table, free, free);
54     free(table);
55   }
56   return rv;
57 }
58
59 int main(int argc, char **argv) {
60   char conf_str[1024];
61
62   parse_clargs(argc, argv);
63
64   /* First initialize logging, so we can log errors */
65   noit_log_init();
66   noit_log_stream_add_stream(noit_debug, noit_stderr);
67   noit_log_stream_add_stream(noit_error, noit_stderr);
68
69   /* Next load the configs */
70   noit_conf_init(APPNAME);
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(APPNAME);
77   if(debug)
78     noit_debug->enabled = 1;
79
80   /* Lastly, run through all other system inits */
81   if(!noit_conf_get_stringbuf(NULL, "/" APPNAME "/eventer/@implementation",
82                               conf_str, sizeof(conf_str))) {
83     noitL(noit_stderr, "Cannot find '%s' in configuration\n",
84           "/" APPNAME "/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_listener_init(APPNAME);
101   stratcon_jlog_streamer_init(APPNAME);
102
103   eventer_loop();
104   return 0;
105 }
Note: See TracBrowser for help on using the browser.