diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 954f2cb8a30b2d4bff75c9580f2e6c9be1f9b909..f04607f6fadf931b836d36fa7dc6fa4998f8bd71 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -727,10 +727,6 @@ void read_history() { char f_history[TSDB_FILENAME_LEN]; get_history_path(f_history); - if (access(f_history, R_OK) == -1) { - return; - } - FILE *f = fopen(f_history, "r"); if (f == NULL) { fprintf(stderr, "Opening file %s\n", f_history); @@ -809,14 +805,6 @@ void source_file(TAOS *con, char *fptr) { return; } - if (access(fname, R_OK) != 0) { - fprintf(stderr, "ERROR: file %s is not readable\n", fptr); - - wordfree(&full_path); - free(cmd); - return; - } - FILE *f = fopen(fname, "r"); if (f == NULL) { fprintf(stderr, "ERROR: failed to open file %s\n", fname); diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index f03b46ac470e828bdb62b76d31cea796c83fed81..d96f80ed206a2f5541daf7bbbd0f4036da4ab7b3 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -646,10 +646,9 @@ int taosDumpDb(SDbInfo *dbInfo, SDumpArguments *arguments, FILE *fp) { taosDumpTable(tableRecord.name, tableRecord.metric, arguments, fp); } - tclose(fd); - remove(".table.tmp"); + close(fd); - return 0; + return remove(".table.tmp"); } void taosDumpCreateTableClause(STableDef *tableDes, int numOfCols, SDumpArguments *arguments, FILE *fp) { diff --git a/src/plugins/http/src/gcHandle.c b/src/plugins/http/src/gcHandle.c index fbe6757ccbcdea09bce8d8feabfae95e2691a549..41209801233c6621c9f5a7d233c7d01718d54ba4 100644 --- a/src/plugins/http/src/gcHandle.c +++ b/src/plugins/http/src/gcHandle.c @@ -22,9 +22,27 @@ #include "taosdef.h" static HttpDecodeMethod gcDecodeMethod = {"grafana", gcProcessRequest}; -static HttpEncodeMethod gcHeartBeatMethod = {NULL, gcSendHeartBeatResp, NULL, NULL, NULL, NULL, NULL, NULL}; +static HttpEncodeMethod gcHeartBeatMethod = { + .startJsonFp = NULL, + .stopJsonFp = gcSendHeartBeatResp, + .buildQueryJsonFp = NULL, + .buildAffectRowJsonFp = NULL, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; + static HttpEncodeMethod gcQueryMethod = { - NULL, gcStopQueryJson, gcBuildQueryJson, NULL, gcInitQueryJson, gcCleanQueryJson, NULL, NULL}; + .startJsonFp = NULL, + .stopJsonFp = gcStopQueryJson, + .buildQueryJsonFp = gcBuildQueryJson, + .buildAffectRowJsonFp = NULL, + .initJsonFp = gcInitQueryJson, + .cleanJsonFp = gcCleanQueryJson, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; void gcInitHandle(HttpServer* pServer) { httpAddMethod(pServer, &gcDecodeMethod); } diff --git a/src/plugins/http/src/httpSql.c b/src/plugins/http/src/httpSql.c index af9ad8e38acdfdf7752bbdf14ea8daf54bcc2152..6ff93b3e8a728d72d33e717991d9a1917e5e3c55 100644 --- a/src/plugins/http/src/httpSql.c +++ b/src/plugins/http/src/httpSql.c @@ -87,7 +87,7 @@ void httpProcessMultiSqlCallBack(void *param, TAOS_RES *result, int code) { } if (code < 0) { - if (encode->checkFinishedFp != NULL && !encode->checkFinishedFp(pContext, singleCmd, code >= 0 ? 0 : code)) { + if (encode->checkFinishedFp != NULL && !encode->checkFinishedFp(pContext, singleCmd, -code)) { singleCmd->code = code; httpTrace("context:%p, fd:%d, ip:%s, user:%s, process pos jump to:%d, last code:%s, last sql:%s", pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos + 1, tstrerror(code), sql); diff --git a/src/plugins/http/src/restHandle.c b/src/plugins/http/src/restHandle.c index a2dc7d06a1a75fd51fa17f910599b67ea6129575..d481a654d89e41ee296645fe32cb5fff38abf521 100644 --- a/src/plugins/http/src/restHandle.c +++ b/src/plugins/http/src/restHandle.c @@ -22,11 +22,37 @@ static HttpDecodeMethod restDecodeMethod = {"rest", restProcessRequest}; static HttpDecodeMethod restDecodeMethod2 = {"restful", restProcessRequest}; static HttpEncodeMethod restEncodeSqlTimestampMethod = { - restStartSqlJson, restStopSqlJson, restBuildSqlTimestampJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL}; + .startJsonFp = restStartSqlJson, + .stopJsonFp = restStopSqlJson, + .buildQueryJsonFp = restBuildSqlTimestampJson, + .buildAffectRowJsonFp = restBuildSqlAffectRowsJson, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; + static HttpEncodeMethod restEncodeSqlLocalTimeStringMethod = { - restStartSqlJson, restStopSqlJson, restBuildSqlLocalTimeStringJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL}; + .startJsonFp = restStartSqlJson, + .stopJsonFp = restStopSqlJson, + .buildQueryJsonFp = restBuildSqlLocalTimeStringJson, + .buildAffectRowJsonFp = restBuildSqlAffectRowsJson, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; + static HttpEncodeMethod restEncodeSqlUtcTimeStringMethod = { - restStartSqlJson, restStopSqlJson, restBuildSqlUtcTimeStringJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL}; + .startJsonFp = restStartSqlJson, + .stopJsonFp = restStopSqlJson, + .buildQueryJsonFp = restBuildSqlUtcTimeStringJson, + .buildAffectRowJsonFp = restBuildSqlAffectRowsJson, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; void restInitHandle(HttpServer* pServer) { httpAddMethod(pServer, &restDecodeMethod); diff --git a/src/plugins/http/src/tgHandle.c b/src/plugins/http/src/tgHandle.c index ffb2ccb2f932a715da56364069235cd0b98ea0d3..c6a2230bfb28fb3bffb5d760937423291190a787 100644 --- a/src/plugins/http/src/tgHandle.c +++ b/src/plugins/http/src/tgHandle.c @@ -62,9 +62,16 @@ #define TG_MAX_SORT_TAG_SIZE 20 static HttpDecodeMethod tgDecodeMethod = {"telegraf", tgProcessRquest}; -static HttpEncodeMethod tgQueryMethod = {tgStartQueryJson, tgStopQueryJson, NULL, - tgBuildSqlAffectRowsJson, tgInitQueryJson, tgCleanQueryJson, - tgCheckFinished, tgSetNextCmd}; +static HttpEncodeMethod tgQueryMethod = { + .startJsonFp = tgStartQueryJson, + .stopJsonFp = tgStopQueryJson, + .buildQueryJsonFp = NULL, + .buildAffectRowJsonFp = tgBuildSqlAffectRowsJson, + .initJsonFp = tgInitQueryJson, + .cleanJsonFp = tgCleanQueryJson, + .checkFinishedFp = tgCheckFinished, + .setNextCmdFp = tgSetNextCmd +}; static const char DEFAULT_TELEGRAF_CFG[] = "{\"metrics\":[" @@ -303,7 +310,7 @@ bool tgGetUserFromUrl(HttpContext *pContext) { return false; } - strcpy(pContext->user, pParser->path[TG_USER_URL_POS].pos); + tstrncpy(pContext->user, pParser->path[TG_USER_URL_POS].pos, TSDB_USER_LEN); return true; } diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index 47521fc36e594b9f4bfde1171c5cfdb0831a9e2e..01a0eabbca39258951f2e0d6c4e098c7bf009be8 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -191,15 +191,14 @@ void taosResetLog() { } static bool taosCheckFileIsOpen(char *logFileName) { - int32_t exist = access(logFileName, F_OK); - if (exist != 0) { - return false; - } - - int32_t fd = open(logFileName, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); + int32_t fd = open(logFileName, O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO); if (fd < 0) { - printf("\nfailed to open log file:%s, reason:%s\n", logFileName, strerror(errno)); - return true; + if (errno == ENOENT) { + return false; + } else { + printf("\nfailed to open log file:%s, reason:%s\n", logFileName, strerror(errno)); + return true; + } } if (taosLockFile(fd)) {