--- mqtt/src/mqttd.c 2012/01/24 10:18:45 1.1.1.1.2.15 +++ mqtt/src/mqttd.c 2012/04/15 21:48:23 1.2.2.3 @@ -7,7 +7,7 @@ io_enableDEBUG; -sl_config cfg; +cfg_root_t cfg; sessions_t Sessions; sched_root_task_t *root; sqlite3 *acc, *pub; @@ -37,8 +37,8 @@ sigHand(int sig) switch (sig) { case SIGHUP: - UnloadConfig(&cfg); - if (!LoadConfig(szCfgName, &cfg)) { + cfgUnloadConfig(&cfg); + if (!cfgLoadConfig(szCfgName, &cfg)) { ioDEBUG(1, "Config reload OK!"); break; } @@ -60,11 +60,12 @@ sigHand(int sig) int main(int argc, char **argv) { - char ch, batch = 0, szStr[STRSIZ]; + char ch, batch = 0; register int i; int sock = -1, ret = 0; struct passwd *pass; struct sigaction sa; + ait_val_t v; TAILQ_INIT(&Sessions); @@ -88,19 +89,20 @@ main(int argc, char **argv) argc -= optind; argv += optind; - if (LoadConfig(szCfgName, &cfg)) { + if (cfgLoadConfig(szCfgName, &cfg)) { printf("Error:: can't load #%d - %s\n", cfg_GetErrno(), cfg_GetError()); return 1; } pthread_mutex_init(&mtx_sess, NULL); pthread_mutex_init(&mtx_pub, NULL); openlog("mqttd", LOG_PID | LOG_CONS, LOG_DAEMON); + /* load 3 plugins */ for (i = 0; i < 3; i++) if (!mqttLoadRTLM(&cfg, i)) { printf("Error:: Can't load RTL module\n"); while (i--) mqttUnloadRTLM(i); - UnloadConfig(&cfg); + cfgUnloadConfig(&cfg); closelog(); pthread_mutex_destroy(&mtx_pub); pthread_mutex_destroy(&mtx_sess); @@ -153,7 +155,7 @@ main(int argc, char **argv) goto end; } else - ioVERBOSE(1) printf("Start service in batch mode ...\n"); + ioDEBUG(1, "Start service in batch mode ..."); memset(&sa, 0, sizeof sa); sigemptyset(&sa.sa_mask); @@ -162,15 +164,16 @@ main(int argc, char **argv) sigaction(SIGTERM, &sa, NULL); sigaction(SIGCHLD, &sa, NULL); sigaction(SIGPIPE, &sa, NULL); - ioDEBUG(2, "Service is ready for start engine ..."); + ioDEBUG(2, "Service is ready for starting engine ..."); if ((sock = srv_Socket(&cfg)) == -1) { ret = 4; goto end; } - cfg_LoadAttribute(&cfg, CFG("mqttd"), CFG("user"), CFG(szStr), sizeof szStr, MQTT_USER); - pass = getpwnam(szStr); + cfg_loadAttribute(&cfg, "mqttd", "user", &v, MQTT_USER); + pass = getpwnam(AIT_GET_STR(&v)); + AIT_FREE_VAL(&v); if (pass) { setgid(pass->pw_gid); setuid(pass->pw_uid); @@ -178,15 +181,16 @@ main(int argc, char **argv) } if (!(root = schedBegin())) { - printf("Error:: scheduler #%d - %s\n", sched_GetErrno(), sched_GetError()); + ioLIBERR(sched); ret = 6; goto end; } + /* go catch the cat ... */ Run(sock); schedEnd(&root); -end: +end: /* free all resources */ srv_Close(sock); call.CloseLOG(logg); call.ClosePUB(pub); @@ -194,7 +198,7 @@ end: for (i = 0; i < 3; i++) mqttUnloadRTLM(i); closelog(); - UnloadConfig(&cfg); + cfgUnloadConfig(&cfg); pthread_mutex_destroy(&mtx_pub); pthread_mutex_destroy(&mtx_sess); return ret;