From c9c2763dd4302cf013d0a7238881001d214a8b03 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Fri, 8 Jan 2021 17:24:43 +0800 Subject: [PATCH] [TD-2705] fix: provide cmdline info when a shutdown signal received. --- src/dnode/src/dnodeSystem.c | 2 +- src/os/inc/osSysinfo.h | 1 + src/os/src/linux/linuxEnv.c | 20 +++++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/dnode/src/dnodeSystem.c b/src/dnode/src/dnodeSystem.c index 36232893b5..a4d7e791e6 100644 --- a/src/dnode/src/dnodeSystem.c +++ b/src/dnode/src/dnodeSystem.c @@ -160,7 +160,7 @@ static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context) { 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", signum, sigInfo->si_pid); + 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}}; diff --git a/src/os/inc/osSysinfo.h b/src/os/inc/osSysinfo.h index 2b98f8b4bf..b592a6c679 100644 --- a/src/os/inc/osSysinfo.h +++ b/src/os/inc/osSysinfo.h @@ -32,6 +32,7 @@ void taosPrintOsInfo(); int taosSystem(const char * cmd) ; void taosKillSystem(); bool taosGetSystemUid(char *uid); +char *taosGetCmdlineByPID(int pid); // TAOS_OS_FUNC_SYSINFO_CORE void taosSetCoreDump(); diff --git a/src/os/src/linux/linuxEnv.c b/src/os/src/linux/linuxEnv.c index 14b40a1f18..5772885cb4 100644 --- a/src/os/src/linux/linuxEnv.c +++ b/src/os/src/linux/linuxEnv.c @@ -39,4 +39,22 @@ void osInit() { strcpy(tsDnodeDir, ""); strcpy(tsMnodeDir, ""); strcpy(tsOsName, "Linux"); -} \ No newline at end of file +} + +char cmdline[1024]; + +char *taosGetCmdlineByPID(int pid) +{ + sprintf(cmdline, "/proc/%d/cmdline",pid); + FILE* f = fopen(cmdline,"r"); + if(f){ + size_t size; + size = fread(cmdline, sizeof(char), 1024, f); + if(size>0){ + if('\n'==cmdline[size-1]) + cmdline[size-1]='\0'; + } + fclose(f); + } + return cmdline; +} -- GitLab