diff --git a/cmake/cmake.options b/cmake/cmake.options index 8b33353632f16039dba2fe968caf4b912fd15143..d2dd48c1a0f00fcbb342b06a61b77f9018c59d7b 100644 --- a/cmake/cmake.options +++ b/cmake/cmake.options @@ -47,15 +47,21 @@ IF(${TD_WINDOWS}) ) option( - BUILD_TEST - "If build unit tests using googletest" - ON - ) + BUILD_TEST + "If build unit tests using googletest" + ON + ) option( - TDENGINE_3 - "TDengine 3.x" - ON + TDENGINE_3 + "TDengine 3.x for taos-tools" + ON + ) + + option( + BUILD_CRASHDUMP + "If build crashdump on Windows" + ON ) ELSEIF (TD_DARWIN_64) diff --git a/cmake/crashdump_CMakeLists.txt.in b/cmake/crashdump_CMakeLists.txt.in new file mode 100644 index 0000000000000000000000000000000000000000..af4b551159481a1f7fceabd59d18fe767569de45 --- /dev/null +++ b/cmake/crashdump_CMakeLists.txt.in @@ -0,0 +1,12 @@ + +# crashdump +ExternalProject_Add(crashdump + GIT_REPOSITORY https://github.com/Arnavion/crashdump.git + GIT_TAG master + SOURCE_DIR "${TD_CONTRIB_DIR}/crashdump" + BINARY_DIR "${TD_CONTRIB_DIR}/crashdump" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" + ) diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index 384cffc08c7ba85658826be20cc9276ad3177b5f..83246289f114c2d4fe4f43fcea54231e1f24a821 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -120,6 +120,11 @@ if(${BUILD_WITH_NURAFT}) cat("${TD_SUPPORT_DIR}/nuraft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) endif(${BUILD_WITH_NURAFT}) +# crashdump +if(${BUILD_CRASHDUMP}) + cat("${TD_SUPPORT_DIR}/crashdump_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) +endif(${BUILD_CRASHDUMP}) + # addr2line if(${BUILD_ADDR2LINE}) if(NOT ${TD_WINDOWS}) @@ -257,6 +262,16 @@ if(${BUILD_PTHREAD}) target_link_libraries(pthread INTERFACE libpthreadVC3) endif() +# crashdump +if(${BUILD_CRASHDUMP}) + add_executable(dumper "crashdump/dumper/dumper.c") + target_link_libraries(dumper User32.lib dbghelp.lib) + file(READ "crashdump/crasher/crasher.c" CRASHDUMP_CONTENT) + string(REPLACE "main(" "main_crashdump(" CRASHDUMP_CONTENT "${CRASHDUMP_CONTENT}") + file(WRITE "crashdump/crasher/crasher.c" "${CRASHDUMP_CONTENT}") + add_library(crashdump STATIC "crashdump/crasher/crasher.c") +endif() + # iconv if(${BUILD_WITH_ICONV}) add_library(iconv STATIC iconv/win_iconv.c) diff --git a/packaging/tools/make_install.bat b/packaging/tools/make_install.bat index 64f30b8465bc48951603fd674eccafc2a5e73432..0f9e836ae2a6cfd80b598b363ae489cb08345d6c 100644 --- a/packaging/tools/make_install.bat +++ b/packaging/tools/make_install.bat @@ -1,6 +1,7 @@ @echo off goto %1 :needAdmin -mshta vbscript:createobject("shell.application").shellexecute("%~s0",":hasAdmin","","runas",1)(window.close)&goto :eof +mshta vbscript:createobject("shell.application").shellexecute("%~s0",":hasAdmin","","runas",1)(window.close)&& echo To start/stop TDengine with administrator privileges: sc start/stop taosd &goto :eof :hasAdmin -cp -f C:\\TDengine\\driver\\taos.dll C:\\Windows\\System32 \ No newline at end of file +cp -f C:\\TDengine\\driver\\taos.dll C:\\Windows\\System32 +sc query "taosd" >nul || sc create "taosd" binPath= "C:\\TDengine\\taosd.exe --win_service" start= DEMAND diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt index 129e20e5de89caf1ad892205b98106d33a14ab19..f52edbe71f151398c5ebdcd705eab376f2318aae 100644 --- a/source/client/CMakeLists.txt +++ b/source/client/CMakeLists.txt @@ -20,11 +20,6 @@ target_link_libraries( ) if(TD_WINDOWS) - set_target_properties(taos - PROPERTIES - LINK_FLAGS - /DEF:${CMAKE_CURRENT_SOURCE_DIR}/src/taos.def - ) INCLUDE_DIRECTORIES(jni/windows) INCLUDE_DIRECTORIES(jni/windows/win32) INCLUDE_DIRECTORIES(jni/windows/win32/bridge) diff --git a/source/client/src/taos.def b/source/client/src/taos.def deleted file mode 100644 index 994dd75090f9900addf5af5fe692661dd4110a4b..0000000000000000000000000000000000000000 --- a/source/client/src/taos.def +++ /dev/null @@ -1,81 +0,0 @@ -taos_cleanup -taos_options -taos_set_config -taos_init -taos_connect -taos_connect_l -taos_connect_auth -taos_close -taos_data_type -taos_stmt_init -taos_stmt_prepare -taos_stmt_set_tbname_tags -taos_stmt_set_tbname -taos_stmt_set_sub_tbname -taos_stmt_is_insert -taos_stmt_num_params -taos_stmt_get_param -taos_stmt_bind_param -taos_stmt_bind_param_batch -taos_stmt_bind_single_param_batch -taos_stmt_add_batch -taos_stmt_execute -taos_stmt_use_result -taos_stmt_close -taos_stmt_errstr -taos_stmt_affected_rows -taos_stmt_affected_rows_once -taos_query -taos_query_l -taos_fetch_row -taos_result_precision -taos_free_result -taos_field_count -taos_num_fields -taos_affected_rows -taos_fetch_fields -taos_select_db -taos_print_row -taos_stop_query -taos_is_null -taos_is_update_query -taos_fetch_block -taos_fetch_block_s -taos_fetch_raw_block -taos_get_column_data_offset -taos_validate_sql -taos_reset_current_db -taos_fetch_lengths -taos_result_block -taos_get_server_info -taos_get_client_info -taos_errstr -taos_errno -taos_query_a -taos_fetch_rows_a -taos_subscribe -taos_consume -taos_unsubscribe -taos_load_table_info -taos_schemaless_insert -tmq_list_new -tmq_list_append -tmq_list_destroy -tmq_list_get_size -tmq_list_to_c_array -tmq_consumer_new -tmq_err2str -tmq_subscribe -tmq_unsubscribe -tmq_subscription -tmq_consumer_poll -tmq_consumer_close -tmq_commit -tmq_conf_new -tmq_conf_set -tmq_conf_destroy -tmq_conf_set_offset_commit_cb -tmq_get_topic_name -tmq_get_vgroup_id -tmq_create_stream -taos_check_server_status \ No newline at end of file diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index 013cc05c65795f92084fc157ba056acd0561073e..34c3b40556361297f8d368bf47e5ed8800bd8547 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -27,6 +27,9 @@ #define DM_VERSION "Print program version." #define DM_EMAIL "" static struct { +#ifdef WINDOWS + bool winServiceMode; +#endif bool dumpConfig; bool generateGrant; bool printAuth; @@ -93,6 +96,10 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) { global.dumpConfig = true; } else if (strcmp(argv[i], "-V") == 0) { global.printVersion = true; + #ifdef WINDOWS + } else if (strcmp(argv[i], "--win_service") == 0) { + global.winServiceMode = true; + #endif } else if (strcmp(argv[i], "-e") == 0) { global.envCmd[cmdEnvIndex] = argv[++i]; cmdEnvIndex++; @@ -169,6 +176,18 @@ int main(int argc, char const *argv[]) { return -1; } +#ifdef WINDOWS + int mainWindows(int argc,char** argv); + if (global.winServiceMode) { + stratWindowsService(mainWindows); + } else { + return mainWindows(argc, argv); + } + return 0; +} +int mainWindows(int argc,char** argv) { +#endif + if (global.generateGrant) { dmGenerateGrant(); taosCleanupArgs(); diff --git a/source/os/CMakeLists.txt b/source/os/CMakeLists.txt index f773e4ff589d1ecc6b10240452d659e16119706f..2a9d0c8535b6cc8ccde0a75013d0fbc7187e7d41 100644 --- a/source/os/CMakeLists.txt +++ b/source/os/CMakeLists.txt @@ -41,7 +41,7 @@ target_link_libraries( ) if(TD_WINDOWS) target_link_libraries( - os PUBLIC ws2_32 iconv msvcregex wcwidth winmm + os PUBLIC ws2_32 iconv msvcregex wcwidth winmm crashdump ) elseif(TD_DARWIN_64) target_link_libraries( diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index fa94bc6a13d289349f687fd214247151c6a2d6c9..812e4c28020f34e0d336fb0e6a413486cb61529d 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -91,6 +91,7 @@ LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) { return EXCEPTION_CONTINUE_SEARCH; } +LONG WINAPI exceptionHandler(LPEXCEPTION_POINTERS exception); #elif defined(_TD_DARWIN_64) @@ -841,7 +842,8 @@ char *taosGetCmdlineByPID(int pid) { void taosSetCoreDump(bool enable) { #ifdef WINDOWS - SetUnhandledExceptionFilter(&FlCrashDump); + SetUnhandledExceptionFilter(exceptionHandler); + // SetUnhandledExceptionFilter(&FlCrashDump); #elif defined(_TD_DARWIN_64) #else if (!enable) return; diff --git a/source/os/src/osSystem.c b/source/os/src/osSystem.c index ad7fa571828b0ec682c1238a20bf5dcf0b8563dc..c86cd19e32df27cb471c6fe1893f6e39887166ec 100644 --- a/source/os/src/osSystem.c +++ b/source/os/src/osSystem.c @@ -18,6 +18,63 @@ #include "os.h" #if defined(WINDOWS) +typedef void (*MainWindows)(int argc,char** argv); +MainWindows mainWindowsFunc = NULL; + +SERVICE_STATUS ServiceStatus; +SERVICE_STATUS_HANDLE hServiceStatusHandle; +void WINAPI windowsServiceCtrlHandle(DWORD request) { + switch (request) { + case SERVICE_CONTROL_STOP: + case SERVICE_CONTROL_SHUTDOWN: + raise(SIGINT); + ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING; + if (!SetServiceStatus(hServiceStatusHandle, &ServiceStatus)) { + DWORD nError = GetLastError(); + printf("failed to send stopped status to windows service: %d",nError); + } + break; + default: + return; + } +} +void WINAPI mainWindowsService(int argc,char** argv) { + int ret = 0; + ServiceStatus.dwServiceType = SERVICE_WIN32; + ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; + ServiceStatus.dwCurrentState = SERVICE_START_PENDING; + ServiceStatus.dwWin32ExitCode = 0; + ServiceStatus.dwCheckPoint = 0; + ServiceStatus.dwWaitHint = 0; + ServiceStatus.dwServiceSpecificExitCode = 0; + hServiceStatusHandle = RegisterServiceCtrlHandler("taosd", &windowsServiceCtrlHandle); + if (hServiceStatusHandle == 0) { + DWORD nError = GetLastError(); + printf("failed to register windows service ctrl handler: %d",nError); + } + + ServiceStatus.dwCurrentState = SERVICE_RUNNING; + if (SetServiceStatus(hServiceStatusHandle, &ServiceStatus)) { + DWORD nError = GetLastError(); + printf("failed to send running status to windows service: %d",nError); + } + if (mainWindowsFunc != NULL) mainWindowsFunc(argc, argv); + ServiceStatus.dwCurrentState = SERVICE_STOPPED; + if (!SetServiceStatus(hServiceStatusHandle, &ServiceStatus)) { + DWORD nError = GetLastError(); + printf("failed to send stopped status to windows service: %d",nError); + } +} +void stratWindowsService(MainWindows mainWindows) { + mainWindowsFunc = mainWindows; + SERVICE_TABLE_ENTRY ServiceTable[2]; + ServiceTable[0].lpServiceName = "taosd"; + ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)mainWindowsService; + ServiceTable[1].lpServiceName = NULL; + ServiceTable[1].lpServiceProc = NULL; + StartServiceCtrlDispatcher(ServiceTable); +} + #elif defined(_TD_DARWIN_64) #else #include