diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index bc2c42cf79eb8f2be91f21ce6fc938dd32e84992..13539a9b197875210d76c86bd93ec986190c0c37 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -52,7 +52,9 @@ static bool validPassword(const char* passwd) { static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, const char *auth, const char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int), void *param, TAOS **taos) { - taos_init(); + if (taos_init()) { + return NULL; + } if (!validUserName(user)) { terrno = TSDB_CODE_TSC_INVALID_USER_LENGTH; diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 6a4ab416aeab5f28414c12511ecb777ec477f252..4da922dadd1cf7fa55c4c7423568045886e61ab2 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -47,6 +47,7 @@ void *tscRpcCache; // cache to keep rpc obj int32_t tscNumOfThreads = 1; // num of rpc threads static pthread_mutex_t rpcObjMutex; // mutex to protect open the rpc obj concurrently static pthread_once_t tscinit = PTHREAD_ONCE_INIT; +static volatile int tscInitRes = 0; void tscCheckDiskUsage(void *UNUSED_PARAM(para), void *UNUSED_PARAM(param)) { taosGetDisk(); @@ -137,7 +138,11 @@ void taos_init_imp(void) { } taosReadGlobalCfg(); - taosCheckGlobalCfg(); + if (taosCheckGlobalCfg()) { + tscInitRes = -1; + return; + } + taosInitNotes(); rpcInit(); @@ -159,6 +164,7 @@ void taos_init_imp(void) { tscQhandle = taosInitScheduler(queueSize, tscNumOfThreads, "tsc"); if (NULL == tscQhandle) { tscError("failed to init scheduler"); + tscInitRes = -1; return; } @@ -187,7 +193,7 @@ void taos_init_imp(void) { tscDebug("client is initialized successfully"); } -void taos_init() { pthread_once(&tscinit, taos_init_imp); } +int taos_init() { pthread_once(&tscinit, taos_init_imp); return tscInitRes;} // this function may be called by user or system, or by both simultaneously. void taos_cleanup(void) { diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index fb6d7459318174bc864b8d0cc813df3d3e65dc00..5bb4a285f4cf5645766f11e520060669f2467ce3 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -373,6 +373,23 @@ static void taosCheckDataDirCfg() { } } +static int32_t taosCheckTmpDir(void) { + if (strlen(tsTempDir) <= 0){ + uError("tempDir is not set"); + return -1; + } + + DIR *dir = opendir(tsTempDir); + if (dir == NULL) { + uError("can not open tempDir:%s, error:%s", tsTempDir, strerror(errno)); + return -1; + } + + closedir(dir); + + return 0; +} + static void doInitGlobalConfig(void) { osInit(); srand(taosSafeRand()); @@ -1488,6 +1505,11 @@ int32_t taosCheckGlobalCfg() { } taosCheckDataDirCfg(); + + if (taosCheckTmpDir()) { + return -1; + } + taosGetSystemInfo(); tsSetLocale(); diff --git a/src/inc/taos.h b/src/inc/taos.h index 05d390ffd0cdf4bf0acab82714c867777d9593d4..cd8e116053bd9adabda9a1eeeb20c6d92679d99d 100644 --- a/src/inc/taos.h +++ b/src/inc/taos.h @@ -68,7 +68,7 @@ typedef struct taosField { #define DLL_EXPORT #endif -DLL_EXPORT void taos_init(); +DLL_EXPORT int taos_init(); DLL_EXPORT void taos_cleanup(void); DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...); DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 8e6c4d8817904bd381bd95acc24592e5e5e533dc..31db1e797142a458b1252eb5232ba2898e18435a 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -76,7 +76,11 @@ TAOS *shellInit(SShellArguments *args) { args->user = TSDB_DEFAULT_USER; } - taos_init(); + if (taos_init()) { + printf("failed to init taos\n"); + fflush(stdout); + return NULL; + } // Connect to the database. TAOS *con = NULL; diff --git a/src/kit/shell/src/shellMain.c b/src/kit/shell/src/shellMain.c index 49de42796caf31f426c60945d7d252fd10372f28..4c7e550760cecb7c045cb8c94fc431cb5f91812b 100644 --- a/src/kit/shell/src/shellMain.c +++ b/src/kit/shell/src/shellMain.c @@ -110,7 +110,10 @@ int main(int argc, char* argv[]) { } if (args.netTestRole && args.netTestRole[0] != 0) { - taos_init(); + if (taos_init()) { + printf("Failed to init taos"); + exit(EXIT_FAILURE); + } taosNetTest(args.netTestRole, args.host, args.port, args.pktLen); exit(0); } diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index abcadd64b10e21fb6fe14767d374bfacbf744101..8544c8a5eaeecc7748d2d8ea5a41630643d2771c 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -711,7 +711,11 @@ int main(int argc, char *argv[]) { fprintf(fp, "###################################################################\n\n"); fprintf(fp, "| WRecords | Records/Second | Requests/Second | WLatency(ms) |\n"); - taos_init(); + if (taos_init()) { + fprintf(stderr, "Failed to init taos\n"); + return 1; + } + TAOS *taos = taos_connect(ip_addr, user, pass, NULL, port); if (taos == NULL) { fprintf(stderr, "Failed to connect to TDengine, reason:%s\n", taos_errstr(NULL)); diff --git a/src/kit/taosdemox/taosdemox.c b/src/kit/taosdemox/taosdemox.c index deb2a47645cc05fcb5fce842393147fdce68d9f8..674c9aa0b8473c804c856c9320591359a83520ed 100644 --- a/src/kit/taosdemox/taosdemox.c +++ b/src/kit/taosdemox/taosdemox.c @@ -1971,7 +1971,11 @@ static int createSuperTable(TAOS * taos, char* dbName, SSuperTable* superTbls, static int createDatabases() { TAOS * taos = NULL; int ret = 0; - taos_init(); + if (taos_init()) { + fprintf(stderr, "Failed to init taos\n"); + exit(-1); + } + taos = taos_connect(g_Dbs.host, g_Dbs.user, g_Dbs.password, NULL, g_Dbs.port); if (taos == NULL) { fprintf(stderr, "Failed to connect to TDengine, reason:%s\n", taos_errstr(NULL)); @@ -4496,7 +4500,11 @@ void *subQueryProcess(void *sarg) { int queryTestProcess() { TAOS * taos = NULL; - taos_init(); + if (taos_init()) { + fprintf(stderr, "Failed to init taos\n"); + exit(-1); + } + taos = taos_connect(g_queryInfo.host, g_queryInfo.user, g_queryInfo.password, NULL, g_queryInfo.port); if (taos == NULL) { fprintf(stderr, "Failed to connect to TDengine, reason:%s\n", taos_errstr(NULL)); @@ -4772,7 +4780,11 @@ int subscribeTestProcess() { } TAOS * taos = NULL; - taos_init(); + if (taos_init()) { + fprintf(stderr, "Failed to init taos\n"); + exit(-1); + } + taos = taos_connect(g_queryInfo.host, g_queryInfo.user, g_queryInfo.password, g_queryInfo.dbName, g_queryInfo.port); if (taos == NULL) { fprintf(stderr, "Failed to connect to TDengine, reason:%s\n", taos_errstr(NULL)); diff --git a/src/plugins/monitor/src/monMain.c b/src/plugins/monitor/src/monMain.c index 424ab0f216162b00d96ae39fcb4351f3ffea75cf..ac80ad62509a755b5b86b65593a90a2730120df8 100644 --- a/src/plugins/monitor/src/monMain.c +++ b/src/plugins/monitor/src/monMain.c @@ -103,7 +103,9 @@ int32_t monInitSystem() { } int32_t monStartSystem() { - taos_init(); + if (taos_init()) { + return -1; + } tsMonitor.start = 1; monExecuteSQLFp = monExecuteSQL; monInfo("monitor module start"); diff --git a/tests/examples/c/demo.c b/tests/examples/c/demo.c index 45ec54680301fd2c941d22d8d67c867b8740c37b..0b12c3d3eabaf9a17ba0859c73e794f2e973dc3b 100644 --- a/tests/examples/c/demo.c +++ b/tests/examples/c/demo.c @@ -62,7 +62,10 @@ int main(int argc, char *argv[]) { } // init TAOS - taos_init(); + if (taos_init()) { + exit(1); + } + TAOS *taos = taos_connect(argv[1], "root", "taosdata", NULL, 0); if (taos == NULL) { printf("failed to connect to server, reason:%s\n", "null taos"/*taos_errstr(taos)*/); diff --git a/tests/examples/c/prepare.c b/tests/examples/c/prepare.c index 7a70b744ee8561459318aa456160a54b8c6270a8..bd650ed64b838d92a03bb5e023c2ca91ac5e2c2e 100644 --- a/tests/examples/c/prepare.c +++ b/tests/examples/c/prepare.c @@ -23,7 +23,10 @@ int main(int argc, char *argv[]) } // init TAOS - taos_init(); + if (taos_init()) { + printf("failed to init taos\n"); + exit(1); + } taos = taos_connect(argv[1], "root", "taosdata", NULL, 0); if (taos == NULL) { diff --git a/tests/examples/c/stream.c b/tests/examples/c/stream.c index 060f5b84ff276579019d3278552e424b2a4198e9..e3053d1969b169767904d595c6ed5615e9d46ce5 100644 --- a/tests/examples/c/stream.c +++ b/tests/examples/c/stream.c @@ -55,7 +55,10 @@ int main(int argc, char *argv[]) } // init TAOS - taos_init(); + if (taos_init()) { + printf("failed to init taos\n"); + exit(1); + } strcpy(db_name, argv[2]); strcpy(tbl_name, argv[3]); diff --git a/tests/examples/c/subscribe.c b/tests/examples/c/subscribe.c index cdd8ddaf7f6c4d2e5088ef36cc00ad77a0c8ebc9..5a402976241133dcef219cb64be7b3492e464aac 100644 --- a/tests/examples/c/subscribe.c +++ b/tests/examples/c/subscribe.c @@ -217,7 +217,10 @@ int main(int argc, char *argv[]) { } // init TAOS - taos_init(); + if (taos_init()) { + printf("failed to init taos\n"); + exit(1); + } TAOS* taos = taos_connect(host, user, passwd, "", 0); if (taos == NULL) { diff --git a/tests/tsim/src/simSystem.c b/tests/tsim/src/simSystem.c index 3a409ecbf900bfe05c423963020d7d3a37cf4771..40937e70532897fa6776965b861a8d678532d8aa 100644 --- a/tests/tsim/src/simSystem.c +++ b/tests/tsim/src/simSystem.c @@ -81,7 +81,9 @@ char *simParseHostName(char *varName) { } bool simSystemInit() { - taos_init(); + if (taos_init()) { + return false; + } taosGetFqdn(simHostName); simInitsimCmdList(); memset(simScriptList, 0, sizeof(SScript *) * MAX_MAIN_SCRIPT_NUM);