#include "global.h"
#include "rtlm.h"
#include "utils.h"
sl_config cfg;
extern char compiled[], compiledby[], compilehost[];
int Verbose;
static void
Usage(void)
{
printf( " -= MQTT Broker =- MQTT Service from ELWIX\n"
"=== %s@%s === Compiled: %s ===\n\n"
"\t-c <config>\tService config\n"
"\t-v\t\tVerbose (more -vvv, more verbose)\n"
"\t-h\t\tHelp! This screen\n\n",
compiledby, compilehost, compiled);
}
int
main(int argc, char **argv)
{
char ch, szCfgName[MAXPATHLEN];
register int i;
sqlite3 *acc = NULL, *pub = NULL;
FILE *logg = NULL;
int sock, ret = 0;
strlcpy(szCfgName, DEFAULT_CONFIG, sizeof szCfgName);
while ((ch = getopt(argc, argv, "hvc:")) != -1)
switch (ch) {
case 'c':
strlcpy(szCfgName, optarg, sizeof szCfgName);
break;
case 'v':
Verbose++;
break;
case 'h':
default:
Usage();
return 1;
}
argc -= optind;
argv += optind;
if (LoadConfig(szCfgName, &cfg)) {
printf("Error:: can't load #%d - %s\n", cfg_GetErrno(), cfg_GetError());
return 1;
}
for (i = 0; i < 3; i++)
if (!mqttLoadRTLM(&cfg, i)) {
printf("Error:: Can't load RTL module\n");
while (i--)
mqttUnloadRTLM(i);
UnloadConfig(&cfg);
return 2;
}
acc = call.OpenACC(&cfg);
if (!acc) {
ret = 3;
goto end;
}
pub = call.OpenPUB(&cfg);
if (!pub) {
ret = 3;
goto end;
}
logg = call.OpenLOG(&cfg);
if (!logg) {
ret = 3;
goto end;
}
if (mqttMkDir(&cfg)) {
printf("Error:: in statedir #%d - %s\n", errno, strerror(errno));
ret = 3;
goto end;
}
VERB(2) printf("Service is ready for start engine ...\n");
if ((sock = srv_Socket(&cfg)) == -1) {
ret = 4;
goto end;
}
srv_Close(sock);
end:
call.CloseLOG(logg);
call.ClosePUB(pub);
call.CloseACC(acc);
for (i = 0; i < 3; i++)
mqttUnloadRTLM(i);
UnloadConfig(&cfg);
return ret;
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>