root/src/stratcond.c

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

prep for jlog transit over SSL

  • 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
18 #define APPNAME "stratcon"
19 static char *config_file = ETC_DIR "/" APPNAME ".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, "/" APPNAME "/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(APPNAME);
70   if(noit_conf_load(config_file) == -1) {
71     fprintf(stderr, "Cannot load config: '%s'\n", config_file);
72   }
73
74   /* Reinitialize the logging system now that we have a config */
75   noit_conf_log_init(APPNAME);
76   if(debug)
77     noit_debug->enabled = 1;
78
79   /* Lastly, run through all other system inits */
80   if(!noit_conf_get_stringbuf(NULL, "/" APPNAME "/eventer/@implementation",
81                               conf_str, sizeof(conf_str))) {
82     noitL(noit_stderr, "Cannot find '%s' in configuration\n",
83           "/" APPNAME "/eventer/@implementation");
84     exit(-1);
85   }
86   if(eventer_choose(conf_str) == -1) {
87     noitL(noit_stderr, "Cannot choose eventer %s\n", conf_str);
88     exit(-1);
89   }
90   if(configure_eventer() != 0) {
91     noitL(noit_stderr, "Cannot configure eventer\n");
92     exit(-1);
93   }
94   if(eventer_init() == -1) {
95     noitL(noit_stderr, "Cannot init eventer %s\n", conf_str);
96     exit(-1);
97   }
98   noit_console_init();
99   noit_listener_init(APPNAME);
100
101   eventer_loop();
102   return 0;
103 }
Note: See TracBrowser for help on using the browser.