Annotation of mqtt/src/mqttd.c, revision 1.1.1.1.2.5
1.1 misho 1: #include "global.h"
1.1.1.1.2.1 misho 2: #include "rtlm.h"
1.1.1.1.2.4 misho 3: #include "utils.h"
1.1.1.1.2.1 misho 4:
5:
6: sl_config cfg;
1.1.1.1.2.2 misho 7: extern char compiled[], compiledby[], compilehost[];
8: int Verbose;
9:
10:
11: static void
12: Usage(void)
13: {
14: printf( " -= MQTT Broker =- MQTT Service from ELWIX\n"
15: "=== %s@%s === Compiled: %s ===\n\n"
16: "\t-c <config>\tService config\n"
17: "\t-v\t\tVerbose (more -vvv, more verbose)\n"
18: "\t-h\t\tHelp! This screen\n\n",
19: compiledby, compilehost, compiled);
20: }
1.1 misho 21:
22:
23: int
24: main(int argc, char **argv)
25: {
1.1.1.1.2.2 misho 26: char ch, szCfgName[MAXPATHLEN];
1.1.1.1.2.3 misho 27: register int i;
28: sqlite3 *acc = NULL, *pub = NULL;
29: FILE *logg = NULL;
1.1.1.1.2.5! misho 30: int sock, ret = 0;
1.1.1.1.2.2 misho 31:
32: strlcpy(szCfgName, DEFAULT_CONFIG, sizeof szCfgName);
33: while ((ch = getopt(argc, argv, "hvc:")) != -1)
34: switch (ch) {
35: case 'c':
36: strlcpy(szCfgName, optarg, sizeof szCfgName);
37: break;
38: case 'v':
39: Verbose++;
40: break;
41: case 'h':
42: default:
43: Usage();
44: return 1;
45: }
46: argc -= optind;
47: argv += optind;
48:
49: if (LoadConfig(szCfgName, &cfg)) {
50: printf("Error:: can't load #%d - %s\n", cfg_GetErrno(), cfg_GetError());
51: return 1;
52: }
1.1.1.1.2.3 misho 53: for (i = 0; i < 3; i++)
54: if (!mqttLoadRTLM(&cfg, i)) {
55: printf("Error:: Can't load RTL module\n");
56: while (i--)
57: mqttUnloadRTLM(i);
58: UnloadConfig(&cfg);
59: return 2;
60: }
61: acc = call.OpenACC(&cfg);
1.1.1.1.2.5! misho 62: if (!acc) {
! 63: ret = 3;
1.1.1.1.2.3 misho 64: goto end;
1.1.1.1.2.5! misho 65: }
1.1.1.1.2.3 misho 66: pub = call.OpenPUB(&cfg);
1.1.1.1.2.5! misho 67: if (!pub) {
! 68: ret = 3;
1.1.1.1.2.3 misho 69: goto end;
1.1.1.1.2.5! misho 70: }
1.1.1.1.2.3 misho 71: logg = call.OpenLOG(&cfg);
1.1.1.1.2.5! misho 72: if (!logg) {
! 73: ret = 3;
1.1.1.1.2.3 misho 74: goto end;
1.1.1.1.2.5! misho 75: }
1.1.1.1.2.3 misho 76:
77: if (mqttMkDir(&cfg)) {
78: printf("Error:: in statedir #%d - %s\n", errno, strerror(errno));
1.1.1.1.2.5! misho 79: ret = 3;
1.1.1.1.2.3 misho 80: goto end;
81: }
82:
83: VERB(2) printf("Service is ready for start engine ...\n");
1.1.1.1.2.2 misho 84:
1.1.1.1.2.5! misho 85: if ((sock = srv_Socket(&cfg)) == -1) {
! 86: ret = 4;
! 87: goto end;
! 88: }
! 89:
! 90: srv_Close(sock);
1.1.1.1.2.3 misho 91: end:
92: call.CloseLOG(logg);
93: call.ClosePUB(pub);
94: call.CloseACC(acc);
95: for (i = 0; i < 3; i++)
96: mqttUnloadRTLM(i);
1.1.1.1.2.2 misho 97: UnloadConfig(&cfg);
1.1.1.1.2.5! misho 98: return ret;
1.1 misho 99: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>