提交 345b1c3a 编写于 作者: B Bomin Zhang

ctrl+c handling in taosd

上级 54f671c0
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "dnodeMain.h" #include "dnodeMain.h"
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context); static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context);
static sem_t exitSem;
int32_t main(int32_t argc, char *argv[]) { int32_t main(int32_t argc, char *argv[]) {
// Set global configuration file // Set global configuration file
...@@ -65,6 +66,11 @@ int32_t main(int32_t argc, char *argv[]) { ...@@ -65,6 +66,11 @@ int32_t main(int32_t argc, char *argv[]) {
#endif #endif
} }
if (sem_init(&exitSem, 0, 0) != 0) {
printf("failed to create exit semphore\n");
exit(EXIT_FAILURE);
}
/* Set termination handler. */ /* Set termination handler. */
struct sigaction act = {{0}}; struct sigaction act = {{0}};
act.sa_flags = SA_SIGINFO; act.sa_flags = SA_SIGINFO;
...@@ -90,9 +96,19 @@ int32_t main(int32_t argc, char *argv[]) { ...@@ -90,9 +96,19 @@ int32_t main(int32_t argc, char *argv[]) {
syslog(LOG_INFO, "Started TDengine service successfully."); syslog(LOG_INFO, "Started TDengine service successfully.");
while (1) { for (int res = sem_wait(&exitSem); res != 0; res = sem_wait(&exitSem)) {
sleep(1000); if (res != EINTR) {
syslog(LOG_ERR, "failed to wait exit semphore: %d", res);
break;
}
} }
dnodeCleanUpSystem();
// close the syslog
syslog(LOG_INFO, "Shut down TDengine service successfully");
dPrint("TDengine is shut down!");
closelog();
return EXIT_SUCCESS;
} }
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context) { static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context) {
...@@ -104,14 +120,21 @@ static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context) { ...@@ -104,14 +120,21 @@ static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context) {
taosCfgDynamicOptions("resetlog"); taosCfgDynamicOptions("resetlog");
return; return;
} }
syslog(LOG_INFO, "Shut down signal is %d", signum); syslog(LOG_INFO, "Shut down signal is %d", signum);
syslog(LOG_INFO, "Shutting down TDengine service..."); syslog(LOG_INFO, "Shutting down TDengine service...");
// clean the system. // clean the system.
dPrint("shut down signal is %d, sender PID:%d", signum, sigInfo->si_pid); dPrint("shut down signal is %d, sender PID:%d", signum, sigInfo->si_pid);
dnodeCleanUpSystem();
// close the syslog // protect the application from receive another signal
syslog(LOG_INFO, "Shut down TDengine service successfully"); struct sigaction act = {{0}};
dPrint("TDengine is shut down!"); act.sa_handler = SIG_IGN;
closelog(); sigaction(SIGTERM, &act, NULL);
exit(EXIT_SUCCESS); sigaction(SIGHUP, &act, NULL);
sigaction(SIGINT, &act, NULL);
sigaction(SIGUSR1, &act, NULL);
sigaction(SIGUSR2, &act, NULL);
// inform main thread to exit
sem_post(&exitSem);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册