diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 2842754e408b56ee8373161c8e21cdfe9dc2ad45..2c5ad2939a0ee7f13a233bcc387f39ba89ba94b4 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -83,6 +83,8 @@ void taos_init_imp() { tscTrace("Local IP address is:%s", tsLocalIp); } + taosSetCoreDump(); + #ifdef CLUSTER tscMgmtIpList.numOfIps = 2; strcpy(tscMgmtIpList.ipstr[0], tsMasterIp); diff --git a/src/os/linux/inc/os.h b/src/os/linux/inc/os.h index 6ecb64eda5b173acd205080318ab95527af9547b..64074104ca5a40c63ee28d86c1cad6e1c7a61551 100644 --- a/src/os/linux/inc/os.h +++ b/src/os/linux/inc/os.h @@ -214,6 +214,9 @@ bool taosSkipSocketCheck(); int64_t str2int64(char *str); +void taosSetCoreDump(); + + #define BUILDIN_CLZL(val) __builtin_clzl(val) #define BUILDIN_CLZ(val) __builtin_clz(val) #define BUILDIN_CTZL(val) __builtin_ctzl(val) diff --git a/src/os/linux/src/tsystem.c b/src/os/linux/src/tsystem.c index ccf9266f9bcddbe747211f8b3ad4ecf2b580c325..0aeebbe58697521a77f0508505ef3903eb24f63d 100644 --- a/src/os/linux/src/tsystem.c +++ b/src/os/linux/src/tsystem.c @@ -25,6 +25,14 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include #include "tglobalcfg.h" #include "tlog.h" @@ -576,4 +584,120 @@ void taosKillSystem() { // SIGINT pPrint("taosd will shut down soon"); kill(tsProcId, 2); -} \ No newline at end of file +} + + +int _sysctl(struct __sysctl_args *args ); +void taosSetCoreDump() { + // 1. set ulimit -c unlimited + struct rlimit rlim; + struct rlimit rlim_new; + if (getrlimit(RLIMIT_CORE, &rlim) == 0) { + pPrint("the old unlimited para: rlim_cur=%d, rlim_max=%d", rlim.rlim_cur, rlim.rlim_max); + rlim_new.rlim_cur = RLIM_INFINITY; + rlim_new.rlim_max = RLIM_INFINITY; + if (setrlimit(RLIMIT_CORE, &rlim_new) != 0) { + pPrint("set unlimited fail, error: %s", strerror(errno)); + rlim_new.rlim_cur = rlim.rlim_max; + rlim_new.rlim_max = rlim.rlim_max; + (void)setrlimit(RLIMIT_CORE, &rlim_new); + } + } + + if (getrlimit(RLIMIT_CORE, &rlim) == 0) { + pPrint("the new unlimited para: rlim_cur=%d, rlim_max=%d", rlim.rlim_cur, rlim.rlim_max); + } + + // 2. set the path for saving core file + struct __sysctl_args args; + int old_usespid; + size_t old_len; + int new_usespid = 1; + size_t new_len = sizeof(new_usespid); + + int name[] = {CTL_KERN, KERN_CORE_USES_PID}; + + memset(&args, 0, sizeof(struct __sysctl_args)); + args.name = name; + args.nlen = sizeof(name)/sizeof(name[0]); + args.oldval = &old_usespid; + args.oldlenp = &old_len; + args.newval = &new_usespid; + args.newlen = new_len; + + old_len = sizeof(old_usespid); + + if (syscall(SYS__sysctl, &args) == -1) { + pPrint("_sysctl(kern_core_uses_pid) fail!"); + } + + pPrint("The old core_uses_pid[%d]: %d", old_len, old_usespid); + + memset(&args, 0, sizeof(struct __sysctl_args)); + args.name = name; + args.nlen = sizeof(name)/sizeof(name[0]); + args.oldval = &old_usespid; + args.oldlenp = &old_len; + + old_len = sizeof(old_usespid); + + if (syscall(SYS__sysctl, &args) == -1) { + pPrint("_sysctl(kern_core_uses_pid) fail!"); + } + + pPrint("The new core_uses_pid[%d]: %d", old_len, old_usespid); + +#if 0 + // 3. set the path for saving core file + int status; + char coredump_dir[32] = "/var/log/taosdump"; + if (opendir(coredump_dir) == NULL) { + status = mkdir(coredump_dir, S_IRWXU | S_IRWXG | S_IRWXO); + if (status) { + pPrint("mkdir fail, error: %s\n", strerror(errno)); + } + } + + // 4. set kernel.core_pattern + struct __sysctl_args args; + char old_corefile[128]; + size_t old_len; + char new_corefile[128] = "/var/log/taosdump/core-%e-%p"; + size_t new_len = sizeof(new_corefile); + + int name[] = {CTL_KERN, KERN_CORE_PATTERN}; + + memset(&args, 0, sizeof(struct __sysctl_args)); + args.name = name; + args.nlen = sizeof(name)/sizeof(name[0]); + args.oldval = old_corefile; + args.oldlenp = &old_len; + args.newval = new_corefile; + args.newlen = new_len; + + old_len = sizeof(old_corefile); + + if (syscall(SYS__sysctl, &args) == -1) { + pPrint("_sysctl(kern_core_pattern) fail!"); + } + + pPrint("The old kern_core_pattern: %*s\n", old_len, old_corefile); + + + memset(&args, 0, sizeof(struct __sysctl_args)); + args.name = name; + args.nlen = sizeof(name)/sizeof(name[0]); + args.oldval = old_corefile; + args.oldlenp = &old_len; + + old_len = sizeof(old_corefile); + + if (syscall(SYS__sysctl, &args) == -1) { + pPrint("_sysctl(kern_core_pattern) fail!"); + } + + pPrint("The new kern_core_pattern: %*s\n", old_len, old_corefile); +#endif + +} + diff --git a/src/system/detail/src/dnodeSystem.c b/src/system/detail/src/dnodeSystem.c index 1b5d9418b424ec0212d58bcaa3e461b69fe371df..888504cce77254dc1df39f8c35b5c0092bdef9cd 100644 --- a/src/system/detail/src/dnodeSystem.c +++ b/src/system/detail/src/dnodeSystem.c @@ -143,6 +143,8 @@ int dnodeInitSystem() { tsPrintGlobalConfig(); dPrint("Server IP address is:%s", tsInternalIp); + taosSetCoreDump(); + signal(SIGPIPE, SIG_IGN); dnodeInitModules();