2019-07-11 08:36:16 +00:00
|
|
|
/*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-03-21 09:29:24 +00:00
|
|
|
#define __USE_XOPEN
|
2022-09-07 02:16:00 +00:00
|
|
|
#include "shellAuto.h"
|
2025-03-20 14:54:29 +00:00
|
|
|
#include "shellInt.h"
|
2022-03-21 09:29:24 +00:00
|
|
|
|
2024-10-27 10:04:21 +00:00
|
|
|
extern SShellObj shell;
|
2023-01-17 03:18:49 +00:00
|
|
|
|
|
|
|
|
void shellCrashHandler(int signum, void *sigInfo, void *context) {
|
|
|
|
|
taosIgnSignal(SIGTERM);
|
|
|
|
|
taosIgnSignal(SIGHUP);
|
|
|
|
|
taosIgnSignal(SIGINT);
|
|
|
|
|
taosIgnSignal(SIGBREAK);
|
|
|
|
|
taosIgnSignal(SIGABRT);
|
|
|
|
|
taosIgnSignal(SIGFPE);
|
|
|
|
|
taosIgnSignal(SIGSEGV);
|
2025-03-20 14:54:29 +00:00
|
|
|
#if !defined(WINDOWS)
|
|
|
|
|
taosIgnSignal(SIGBUS);
|
|
|
|
|
#endif
|
2025-03-14 05:32:13 +00:00
|
|
|
#ifdef USE_REPORT
|
2025-03-20 14:54:29 +00:00
|
|
|
taos_write_crashinfo(signum, sigInfo, context);
|
2025-03-14 05:32:13 +00:00
|
|
|
#endif
|
2023-01-17 03:18:49 +00:00
|
|
|
#ifdef _TD_DARWIN_64
|
|
|
|
|
exit(signum);
|
|
|
|
|
#elif defined(WINDOWS)
|
|
|
|
|
exit(signum);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-20 14:54:29 +00:00
|
|
|
// init arguments
|
|
|
|
|
void initArgument(SShellArgs *pArgs) {
|
|
|
|
|
pArgs->host = NULL;
|
|
|
|
|
pArgs->port = 0;
|
|
|
|
|
pArgs->user = NULL;
|
|
|
|
|
pArgs->database = NULL;
|
|
|
|
|
|
|
|
|
|
// conn mode
|
|
|
|
|
pArgs->dsn = NULL;
|
|
|
|
|
pArgs->connMode = CONN_MODE_INVALID;
|
|
|
|
|
|
|
|
|
|
pArgs->port_inputted = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2025-03-24 13:19:30 +00:00
|
|
|
int code = 0;
|
2023-01-17 03:18:49 +00:00
|
|
|
#if !defined(WINDOWS)
|
|
|
|
|
taosSetSignal(SIGBUS, shellCrashHandler);
|
|
|
|
|
#endif
|
|
|
|
|
taosSetSignal(SIGABRT, shellCrashHandler);
|
|
|
|
|
taosSetSignal(SIGFPE, shellCrashHandler);
|
|
|
|
|
taosSetSignal(SIGSEGV, shellCrashHandler);
|
|
|
|
|
|
2025-03-20 14:54:29 +00:00
|
|
|
initArgument(&shell.args);
|
|
|
|
|
|
2022-04-21 13:09:43 +00:00
|
|
|
if (shellCheckIntSize() != 0) {
|
2022-04-21 13:11:02 +00:00
|
|
|
return -1;
|
2019-07-11 08:36:16 +00:00
|
|
|
}
|
2022-04-21 13:09:43 +00:00
|
|
|
|
|
|
|
|
if (shellParseArgs(argc, argv) != 0) {
|
2022-04-21 13:11:02 +00:00
|
|
|
return -1;
|
2019-07-11 08:36:16 +00:00
|
|
|
}
|
2022-04-21 13:09:43 +00:00
|
|
|
|
|
|
|
|
if (shell.args.is_version) {
|
|
|
|
|
shellPrintVersion();
|
2019-07-11 08:36:16 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-21 13:09:43 +00:00
|
|
|
if (shell.args.is_gen_auth) {
|
|
|
|
|
shellGenerateAuth();
|
|
|
|
|
return 0;
|
2019-07-11 08:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-21 13:09:43 +00:00
|
|
|
if (shell.args.is_help) {
|
2022-04-22 09:59:41 +00:00
|
|
|
shellPrintHelp();
|
2022-04-21 13:09:43 +00:00
|
|
|
return 0;
|
2020-12-10 07:04:08 +00:00
|
|
|
}
|
2025-03-20 14:54:29 +00:00
|
|
|
|
|
|
|
|
if (shell.args.netrole != NULL) {
|
|
|
|
|
shellTestNetWork();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (getDsnEnv() != 0) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-24 13:19:30 +00:00
|
|
|
// first taos_option(TSDB_OPTION_DRIVER ...) no load driver
|
2025-03-22 12:44:07 +00:00
|
|
|
if (setConnMode(shell.args.connMode, shell.args.dsn, false)) {
|
2025-03-20 14:54:29 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-24 13:19:30 +00:00
|
|
|
// second taos_option(TSDB_OPTION_CONFIGDIR ...) set configDir global
|
|
|
|
|
if (configDirShell[0] != 0) {
|
|
|
|
|
code = taos_options(TSDB_OPTION_CONFIGDIR, configDirShell);
|
|
|
|
|
if (code) {
|
|
|
|
|
fprintf(stderr, "failed to set config dir:%s code:[0x%08X]\r\n", configDirShell, code);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
//printf("Load with input config dir:%s\n", configDirShell);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifndef TD_ASTRA
|
|
|
|
|
// dump config
|
|
|
|
|
if (shell.args.is_dump_config) {
|
|
|
|
|
shellDumpConfig();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// taos_init
|
2024-01-22 03:10:00 +00:00
|
|
|
if (taos_init() != 0) {
|
2025-03-20 14:54:29 +00:00
|
|
|
fprintf(stderr, "failed to init shell since %s [0x%08X]\r\n", taos_errstr(NULL), taos_errno(NULL));
|
2024-01-22 03:10:00 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2022-04-27 03:27:27 +00:00
|
|
|
|
2023-04-18 09:12:04 +00:00
|
|
|
// kill heart-beat thread when quit
|
|
|
|
|
taos_set_hb_quit(1);
|
|
|
|
|
|
2025-03-14 05:32:13 +00:00
|
|
|
#ifndef TD_ASTRA
|
2022-04-21 13:09:43 +00:00
|
|
|
if (shell.args.is_startup || shell.args.is_check) {
|
|
|
|
|
shellCheckServerStatus();
|
|
|
|
|
taos_cleanup();
|
|
|
|
|
return 0;
|
2020-12-17 05:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-22 07:50:29 +00:00
|
|
|
if (shell.args.netrole != NULL) {
|
2022-04-21 13:09:43 +00:00
|
|
|
shellTestNetWork();
|
|
|
|
|
taos_cleanup();
|
|
|
|
|
return 0;
|
2019-07-11 08:36:16 +00:00
|
|
|
}
|
2025-03-14 05:32:13 +00:00
|
|
|
#endif
|
2024-01-22 03:10:00 +00:00
|
|
|
// support port feature
|
2022-09-07 02:16:00 +00:00
|
|
|
shellAutoInit();
|
2025-03-14 05:32:13 +00:00
|
|
|
int32_t ret = shellExecute(argc, argv);
|
2022-09-07 02:16:00 +00:00
|
|
|
shellAutoExit();
|
2025-03-20 14:54:29 +00:00
|
|
|
|
2022-09-07 02:16:00 +00:00
|
|
|
return ret;
|
2022-04-19 08:50:25 +00:00
|
|
|
}
|