--- mqtt/src/mqttd.c 2012/04/15 21:44:33 1.2.2.2 +++ mqtt/src/mqttd.c 2012/06/26 14:51:33 1.2.2.10 @@ -11,11 +11,10 @@ cfg_root_t cfg; sessions_t Sessions; sched_root_task_t *root; sqlite3 *acc, *pub; -pthread_mutex_t mtx_sess, mtx_pub; FILE *logg; extern char compiled[], compiledby[], compilehost[]; static char szCfgName[MAXPATHLEN]; -intptr_t Kill; +volatile intptr_t Kill; static void @@ -43,7 +42,8 @@ sigHand(int sig) break; } - syslog(LOG_ERR, "Error:: can't reload #%d - %s", cfg_GetErrno(), cfg_GetError()); + ioLIBERR(cfg); + case SIGINT: case SIGTERM: ioDEBUG(1, "Terminate MQTT service in progress"); Kill++; @@ -93,19 +93,16 @@ main(int argc, char **argv) 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); + mqttUnloadRTLM(acc); + mqttUnloadRTLM(pub); + mqttUnloadRTLM(logg); cfgUnloadConfig(&cfg); closelog(); - pthread_mutex_destroy(&mtx_pub); - pthread_mutex_destroy(&mtx_sess); return 2; } acc = call.OpenACC(&cfg); @@ -124,6 +121,7 @@ main(int argc, char **argv) goto end; } + if (mqttMkDir(&cfg)) { printf("Error:: in statedir #%d - %s\n", errno, strerror(errno)); ret = 3; @@ -155,12 +153,13 @@ 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); sa.sa_handler = sigHand; sigaction(SIGHUP, &sa, NULL); + sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); sigaction(SIGCHLD, &sa, NULL); sigaction(SIGPIPE, &sa, NULL); @@ -181,24 +180,24 @@ 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); call.CloseACC(acc); - for (i = 0; i < 3; i++) - mqttUnloadRTLM(i); - closelog(); + mqttUnloadRTLM(acc); + mqttUnloadRTLM(pub); + mqttUnloadRTLM(logg); cfgUnloadConfig(&cfg); - pthread_mutex_destroy(&mtx_pub); - pthread_mutex_destroy(&mtx_sess); + closelog(); return ret; }