From 82d32cff23f654c39697d9710da997260d6655a0 Mon Sep 17 00:00:00 2001 From: kailixu Date: Tue, 7 Jan 2025 15:37:41 +0800 Subject: [PATCH 1/3] fix: incorrect taos shell prompt when log on taos without sysinfo privilege --- tools/shell/src/shellEngine.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 6c1a972f7e..7fc0f9fb38 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -1180,6 +1180,10 @@ bool shellGetGrantInfo(char *buf) { fprintf(stderr, "Failed to check Server Edition, Reason:0x%04x:%s\r\n\r\n", code, taos_errstr(tres)); } taos_free_result(tres); +#ifdef TD_ENTERPRISE + community = false; + sprintf(buf, "Server is %s, %s and the expire time is unknown.\r\n", TD_PRODUCT_NAME, sinfo); +#endif return community; } From 75c43517be8283e4fcec4c8abc7bb78e75be4c59 Mon Sep 17 00:00:00 2001 From: kailixu Date: Tue, 7 Jan 2025 19:52:13 +0800 Subject: [PATCH 2/3] fix: incorrect prompt when log on taos without sysinfo privilege --- include/util/tdef.h | 8 ++++++++ tools/shell/inc/shellAuto.h | 2 +- tools/shell/src/shellAuto.c | 12 ++++++------ tools/shell/src/shellEngine.c | 36 +++++++++++++++-------------------- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/include/util/tdef.h b/include/util/tdef.h index d11a732754..e7f40f1092 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -665,6 +665,14 @@ typedef enum { ANAL_ALGO_TYPE_END, } EAnalAlgoType; +typedef enum { + TSDB_VERSION_UNKNOWN = 0, + TSDB_VERSION_OSS, + TSDB_VERSION_ENTERPRISE, + TSDB_VERSION_CLOUD, + TSDB_VERSION_END, +} EVersionType; + #define MIN_RESERVE_MEM_SIZE 1024 // MB #ifdef __cplusplus diff --git a/tools/shell/inc/shellAuto.h b/tools/shell/inc/shellAuto.h index c9d631f4b2..7583932ff5 100644 --- a/tools/shell/inc/shellAuto.h +++ b/tools/shell/inc/shellAuto.h @@ -43,7 +43,7 @@ void shellAutoExit(); void callbackAutoTab(char* sqlstr, TAOS* pSql, bool usedb); // introduction -void printfIntroduction(bool community); +void printfIntroduction(EVersionType type); // show enterprise AD at start or end void showAD(bool end); diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index 9fc929a595..87cdc546d2 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -453,7 +453,7 @@ SMatch* lastMatch = NULL; // save last match result int cntDel = 0; // delete byte count after next press tab // show auto tab introduction -void printfIntroduction(bool community) { +void printfIntroduction(EVersionType type) { printf(" ********************************* Tab Completion *************************************\n"); char secondLine[160] = "\0"; sprintf(secondLine, " * The %s CLI supports tab completion for a variety of items, ", shell.info.cusName); @@ -473,11 +473,11 @@ void printfIntroduction(bool community) { printf(" * [ Ctrl + L ] ...... clear the entire screen *\n"); printf(" * [ Ctrl + K ] ...... clear the screen after the cursor *\n"); printf(" * [ Ctrl + U ] ...... clear the screen before the cursor *\n"); - if(community) { - printf(" * ------------------------------------------------------------------------------------ *\n"); - printf(" * You are using TDengine OSS. To experience advanced features, like backup/restore, *\n"); - printf(" * privilege control and more, or receive 7x24 technical support, try TDengine *\n"); - printf(" * Enterprise or TDengine Cloud. Learn more at https://tdengine.com *\n"); + if (type == TSDB_VERSION_OSS) { + printf(" * ------------------------------------------------------------------------------------ *\n"); + printf(" * You are using TDengine OSS. To experience advanced features, like backup/restore, *\n"); + printf(" * privilege control and more, or receive 7x24 technical support, try TDengine *\n"); + printf(" * Enterprise or TDengine Cloud. Learn more at https://tdengine.com *\n"); } printf(" ****************************************************************************************\n\n"); } diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 7fc0f9fb38..1a05d3e1f6 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -58,7 +58,7 @@ static void shellWriteHistory(); static void shellPrintError(TAOS_RES *tres, int64_t st); static bool shellIsCommentLine(char *line); static void shellSourceFile(const char *file); -static bool shellGetGrantInfo(char* buf); +static int32_t shellGetGrantInfo(char* buf); static void shellCleanup(void *arg); static void *shellCancelHandler(void *arg); @@ -1163,9 +1163,9 @@ void shellSourceFile(const char *file) { taosCloseFile(&pFile); } -bool shellGetGrantInfo(char *buf) { - bool community = true; - char sinfo[256] = {0}; +int32_t shellGetGrantInfo(char *buf) { + int32_t verType = TSDB_VERSION_UNKNOWN; + char sinfo[256] = {0}; tstrncpy(sinfo, taos_get_server_info(shell.conn), sizeof(sinfo)); strtok(sinfo, "\r\n"); @@ -1180,11 +1180,7 @@ bool shellGetGrantInfo(char *buf) { fprintf(stderr, "Failed to check Server Edition, Reason:0x%04x:%s\r\n\r\n", code, taos_errstr(tres)); } taos_free_result(tres); -#ifdef TD_ENTERPRISE - community = false; - sprintf(buf, "Server is %s, %s and the expire time is unknown.\r\n", TD_PRODUCT_NAME, sinfo); -#endif - return community; + return verType; } int32_t num_fields = taos_field_count(tres); @@ -1212,12 +1208,12 @@ bool shellGetGrantInfo(char *buf) { memcpy(expired, row[2], fields[2].bytes); if (strcmp(serverVersion, "community") == 0) { - community = true; + verType = TSDB_VERSION_OSS; } else if (strcmp(expiretime, "unlimited") == 0) { - community = false; + verType = TSDB_VERSION_ENTERPRISE; sprintf(buf, "Server is %s, %s and will never expire.\r\n", serverVersion, sinfo); } else { - community = false; + verType = TSDB_VERSION_ENTERPRISE; sprintf(buf, "Server is %s, %s and will expire at %s.\r\n", serverVersion, sinfo, expiretime); } @@ -1225,7 +1221,7 @@ bool shellGetGrantInfo(char *buf) { } fprintf(stdout, "\r\n"); - return community; + return verType; } #ifdef WINDOWS @@ -1385,22 +1381,20 @@ int32_t shellExecute() { #ifdef WEBSOCKET if (!shell.args.restful && !shell.args.cloud) { #endif - char *buf = taosMemoryMalloc(512); - bool community = shellGetGrantInfo(buf); + char buf[512] = {0}; + int32_t verType = shellGetGrantInfo(buf); #ifndef WINDOWS - printfIntroduction(community); + printfIntroduction(verType); #else #ifndef WEBSOCKET - if (community) { + if (verType == TSDB_VERSION_OSS) { showAD(false); } #endif #endif - // printf version - if (!community) { + if (verType == TSDB_VERSION_ENTERPRISE || verType == TSDB_VERSION_CLOUD) { printf("%s\n", buf); } - taosMemoryFree(buf); #ifdef WEBSOCKET } @@ -1416,7 +1410,7 @@ int32_t shellExecute() { } #ifndef WEBSOCKET // commnuity - if (community) { + if (verType == TSDB_VERSION_OSS) { showAD(true); } #endif From 869f037168714ebff8362353783af50793fb3e68 Mon Sep 17 00:00:00 2001 From: kailixu Date: Tue, 7 Jan 2025 19:55:32 +0800 Subject: [PATCH 3/3] fix: incorrect prompt when log on taos without sysinfo privilege --- tools/shell/src/shellEngine.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 1a05d3e1f6..f56a9797f3 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -1392,6 +1392,7 @@ int32_t shellExecute() { } #endif #endif + // printf version if (verType == TSDB_VERSION_ENTERPRISE || verType == TSDB_VERSION_CLOUD) { printf("%s\n", buf); }