提交 65a28796 编写于 作者: S Shengliang Guan

TD-1207

上级 a47e778b
......@@ -19,8 +19,10 @@
#include "tconfig.h"
#include "dnodeMain.h"
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context);
static tsem_t exitSem;
static void siguser1Handler(int32_t signum);
static void siguser2Handler(int32_t signum);
static void sigintHandler(int32_t signum);
int32_t main(int32_t argc, char *argv[]) {
int dump_config = 0;
......@@ -28,7 +30,7 @@ int32_t main(int32_t argc, char *argv[]) {
// Set global configuration file
for (int32_t i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-c") == 0) {
if (i < argc - 1) {
if (i < argc - 1) {
if (strlen(argv[++i]) >= TSDB_FILENAME_LEN) {
printf("config file path overflow");
exit(EXIT_FAILURE);
......@@ -80,8 +82,8 @@ int32_t main(int32_t argc, char *argv[]) {
taosSetRandomFileFailOutput(NULL);
}
} else if (strcmp(argv[i], "--random-file-fail-factor") == 0) {
if ( (i+1) < argc ) {
int factor = atoi(argv[i+1]);
if ((i + 1) < argc) {
int factor = atoi(argv[i + 1]);
printf("The factor of random failure is %d\n", factor);
taosSetRandomFileFailFactor(factor);
} else {
......@@ -93,7 +95,7 @@ int32_t main(int32_t argc, char *argv[]) {
}
if (0 != dump_config) {
tscEmbedded = 1;
tscEmbedded = 1;
taosInitGlobalCfg();
taosReadGlobalLogCfg();
......@@ -112,14 +114,12 @@ int32_t main(int32_t argc, char *argv[]) {
}
/* Set termination handler. */
struct sigaction act = {{0}};
act.sa_flags = SA_SIGINFO;
act.sa_sigaction = signal_handler;
sigaction(SIGTERM, &act, NULL);
sigaction(SIGHUP, &act, NULL);
sigaction(SIGINT, &act, NULL);
sigaction(SIGUSR1, &act, NULL);
sigaction(SIGUSR2, &act, NULL);
taosSetSignal(SIGUSR1, siguser1Handler);
taosSetSignal(SIGUSR2, siguser2Handler);
taosSetSignal(SIGTERM, sigintHandler);
taosSetSignal(SIGHUP, sigintHandler);
taosSetSignal(SIGINT, sigintHandler);
taosSetSignal(SIGABRT, sigintHandler);
// Open /var/log/syslog file to record information.
openlog("TDengine:", LOG_PID | LOG_CONS | LOG_NDELAY, LOG_LOCAL1);
......@@ -147,32 +147,25 @@ int32_t main(int32_t argc, char *argv[]) {
return EXIT_SUCCESS;
}
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context) {
if (signum == SIGUSR1) {
taosCfgDynamicOptions("debugFlag 143");
return;
}
if (signum == SIGUSR2) {
taosCfgDynamicOptions("resetlog");
return;
}
syslog(LOG_INFO, "Shut down signal is %d", signum);
syslog(LOG_INFO, "Shutting down TDengine service...");
// clean the system.
dInfo("shut down signal is %d, sender PID:%d cmdline:%s", signum, sigInfo->si_pid, taosGetCmdlineByPID(sigInfo->si_pid));
// protect the application from receive another signal
struct sigaction act = {{0}};
#ifndef WINDOWS
act.sa_handler = SIG_IGN;
#endif
sigaction(SIGTERM, &act, NULL);
sigaction(SIGHUP, &act, NULL);
sigaction(SIGINT, &act, NULL);
sigaction(SIGUSR1, &act, NULL);
sigaction(SIGUSR2, &act, NULL);
// inform main thread to exit
tsem_post(&exitSem);
static void siguser1Handler(int32_t signum) { taosCfgDynamicOptions("debugFlag 143"); }
static void siguser2Handler(int32_t signum) { taosCfgDynamicOptions("resetlog"); }
static void sigintHandler(int32_t signum) {
// clean the system.
dInfo("shut down signal is %d", signum);
syslog(LOG_INFO, "Shut down signal is %d", signum);
syslog(LOG_INFO, "Shutting down TDengine service...");
// protect the application from receive another signal
taosIgnSignal(SIGUSR1);
taosIgnSignal(SIGUSR2);
taosIgnSignal(SIGTERM);
taosIgnSignal(SIGHUP);
taosIgnSignal(SIGINT);
taosIgnSignal(SIGABRT);
// inform main thread to exit
tsem_post(&exitSem);
}
\ No newline at end of file
......@@ -21,7 +21,7 @@
pthread_t pid;
static tsem_t cancelSem;
void shellQueryInterruptHandler(int32_t signum, siginfo_t *sigInfo, void *context) {
void shellQueryInterruptHandler(int32_t signum) {
tsem_post(&cancelSem);
}
......@@ -130,12 +130,10 @@ int main(int argc, char* argv[]) {
pthread_create(&spid, NULL, cancelHandler, NULL);
/* Interrupt handler. */
struct sigaction act;
memset(&act, 0, sizeof(struct sigaction));
act.sa_handler = shellQueryInterruptHandler;
sigaction(SIGTERM, &act, NULL);
sigaction(SIGINT, &act, NULL);
taosSetSignal(SIGTERM, shellQueryInterruptHandler);
taosSetSignal(SIGINT, shellQueryInterruptHandler);
taosSetSignal(SIGHUP, shellQueryInterruptHandler);
taosSetSignal(SIGABRT, shellQueryInterruptHandler);
/* Get grant information */
shellGetGrantInfo(con);
......
......@@ -62,6 +62,7 @@ extern "C" {
#include "osMemory.h"
#include "osRand.h"
#include "osSemphone.h"
#include "osSignal.h"
#include "osSocket.h"
#include "osString.h"
#include "osSysinfo.h"
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_OS_SIGNAL_H
#define TDENGINE_OS_SIGNAL_H
#ifdef __cplusplus
extern "C" {
#endif
#include "os.h"
#include "taosdef.h"
#include <signal.h>
#ifndef SIGALRM
#define SIGALRM 1234
#endif
#ifndef SIGHUP
#define SIGHUP 1234
#endif
#ifndef SIGCHLD
#define SIGCHLD 1234
#endif
#ifndef SIGUSR1
#define SIGUSR1 1234
#endif
#ifndef SIGUSR2
#define SIGUSR2 1234
#endif
typedef void (*FSignalHandler)(int32_t signum);
void taosSetSignal(int32_t signum, FSignalHandler sigfp);
void taosIgnSignal(int32_t signum);
void taosDflSignal(int32_t signum);
#ifdef __cplusplus
}
#endif
#endif // TDENGINE_TTIME_H
......@@ -191,24 +191,6 @@ int gettimeofday(struct timeval *ptv, void *pTimeZone);
#define PATH_MAX 256
#endif
//for signal, not dispose
#define SIGALRM 1234
#define SIGHUP 1234
#define SIGUSR1 1234
#define SIGUSR2 1234
#define SA_SIGINFO 1234
typedef int sigset_t;
typedef struct siginfo_t {
int si_pid;
} siginfo_t;
struct sigaction {
int sa_flags;
void (*sa_handler)(int32_t signum, siginfo_t *sigInfo, void *context);
void (*sa_sigaction)(int32_t signum, siginfo_t *sigInfo, void *context);
};
int sigaction(int, struct sigaction *, void *);
typedef struct {
int we_wordc;
char **we_wordv;
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "tconfig.h"
#include "tglobal.h"
#include "tulog.h"
#ifndef TAOS_OS_FUNC_SIGNAL
void taosSetSignal(int32_t signum, FSignalHandler sigfp) {
struct sigaction act = {{0}};
act.sa_handler = sigfp;
sigaction(signum, &act, NULL);
}
void taosIgnSignal(int32_t signum) {
signal(signum, SIG_IGN);
}
void taosDflSignal(int32_t signum) {
signal(signum, SIG_DFL);
}
#endif
......@@ -43,6 +43,7 @@ void osInit() {
char cmdline[1024];
char* taosGetCmdlineByPID(int pid) {
#if 0
sprintf(cmdline, "/proc/%d/cmdline", pid);
FILE* f = fopen(cmdline, "r");
if (f) {
......@@ -54,4 +55,7 @@ char* taosGetCmdlineByPID(int pid) {
fclose(f);
}
return cmdline;
#else
return "";
#endif
}
......@@ -235,8 +235,6 @@ int taosSystem(const char *cmd) {
int flock(int fd, int option) { return 0; }
int sigaction(int sig, struct sigaction *d, void *p) { return 0; }
LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) {
typedef BOOL(WINAPI * FxMiniDumpWriteDump)(IN HANDLE hProcess, IN DWORD ProcessId, IN HANDLE hFile,
IN MINIDUMP_TYPE DumpType,
......
......@@ -27,7 +27,7 @@
#include "syncInt.h"
#include "syncTcp.h"
static void arbSignalHandler(int32_t signum, siginfo_t *sigInfo, void *context);
static void arbSignalHandler(int32_t signum);
static void arbProcessIncommingConnection(SOCKET connFd, uint32_t sourceIp);
static void arbProcessBrokenLink(int64_t rid);
static int32_t arbProcessPeerMsg(int64_t rid, void *buffer);
......@@ -69,14 +69,10 @@ int32_t main(int32_t argc, char *argv[]) {
}
/* Set termination handler. */
struct sigaction act = {{0}};
act.sa_flags = SA_SIGINFO;
act.sa_sigaction = arbSignalHandler;
act.sa_handler = arbSignalHandler;
sigaction(SIGTERM, &act, NULL);
sigaction(SIGHUP, &act, NULL);
sigaction(SIGINT, &act, NULL);
taosSetSignal(SIGTERM, arbSignalHandler);
taosSetSignal(SIGINT, arbSignalHandler);
taosSetSignal(SIGHUP, arbSignalHandler);
taosSetSignal(SIGABRT, arbSignalHandler);
tsAsyncLog = 0;
strcat(arbLogPath, "/arbitrator.log");
......@@ -174,16 +170,13 @@ static int32_t arbProcessPeerMsg(int64_t rid, void *buffer) {
return 0;
}
static void arbSignalHandler(int32_t signum, siginfo_t *sigInfo, void *context) {
struct sigaction act = {{0}};
#ifndef WINDOWS
act.sa_handler = SIG_IGN;
#endif
sigaction(SIGTERM, &act, NULL);
sigaction(SIGHUP, &act, NULL);
sigaction(SIGINT, &act, NULL);
static void arbSignalHandler(int32_t signum) {
taosIgnSignal(SIGTERM);
taosIgnSignal(SIGINT);
taosIgnSignal(SIGABRT);
taosIgnSignal(SIGHUP);
sInfo("shut down signal is %d, sender PID:%d", signum, sigInfo->si_pid);
sInfo("shut down signal is %d", signum);
// inform main thread to exit
tsem_post(&tsArbSem);
......
......@@ -314,9 +314,7 @@ bool simExecuteSystemCmd(SScript *script, char *option) {
simError("script:%s, failed to execute %s , code %d, errno:%d %s, repeatTimes:%d", script->fileName, buf, code,
errno, strerror(errno), repeatTimes);
taosMsleep(1000);
#ifdef LINUX
signal(SIGCHLD, SIG_DFL);
#endif
taosDflSignal(SIGCHLD);
if (repeatTimes++ >= 10) {
exit(0);
}
......
......@@ -51,7 +51,7 @@ int32_t main(int32_t argc, char *argv[]) {
}
simInfo("simulator is running ...");
signal(SIGINT, simHandleSignal);
taosSetSignal(SIGINT, simHandleSignal);
SScript *script = simParseScript(scriptFile);
if (script == NULL) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册