From 9176914339eab461802f880d94d3386d062df97f Mon Sep 17 00:00:00 2001 From: Zhiqiang Wang <1296468573@qq.com> Date: Thu, 30 Dec 2021 18:43:51 +0800 Subject: [PATCH] [TD-345](other): win read file binary error. (#9508) --- src/client/src/tscSQLParser.c | 2 +- src/dnode/src/dnodeMain.c | 2 +- src/dnode/src/dnodeTelemetry.c | 2 +- src/inc/tfs.h | 2 +- src/os/src/detail/osRand.c | 2 +- src/os/src/detail/osSysinfo.c | 2 +- src/os/src/linux/linuxEnv.c | 2 +- src/rpc/test/rserver.c | 2 +- src/sync/test/syncServer.c | 2 +- src/tsdb/inc/tsdbFile.h | 4 ++-- src/util/src/tlog.c | 6 +++--- src/util/src/tnote.c | 6 +++--- 12 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 459a2c32be..b5856013f6 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -415,7 +415,7 @@ int32_t readFromFile(char *name, uint32_t *len, void **buf) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } - int fd = open(name, O_RDONLY); + int fd = open(name, O_RDONLY | O_BINARY); if (fd < 0) { tscError("open file %s failed, error:%s", name, strerror(errno)); tfree(*buf); diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index 5291fb73a0..417a3d764d 100644 --- a/src/dnode/src/dnodeMain.c +++ b/src/dnode/src/dnodeMain.c @@ -226,7 +226,7 @@ static void dnodeCheckDataDirOpenned(char *dir) { char filepath[256] = {0}; sprintf(filepath, "%s/.running", dir); - int fd = open(filepath, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); + int fd = open(filepath, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO); if (fd < 0) { dError("failed to open lock file:%s, reason: %s, quit", filepath, strerror(errno)); exit(0); diff --git a/src/dnode/src/dnodeTelemetry.c b/src/dnode/src/dnodeTelemetry.c index 22a6dc5b19..ec09ab5d75 100644 --- a/src/dnode/src/dnodeTelemetry.c +++ b/src/dnode/src/dnodeTelemetry.c @@ -266,7 +266,7 @@ static void* telemetryThread(void* param) { } static void dnodeGetEmail(char* filepath) { - int32_t fd = open(filepath, O_RDONLY); + int32_t fd = open(filepath, O_RDONLY | O_BINARY); if (fd < 0) { return; } diff --git a/src/inc/tfs.h b/src/inc/tfs.h index e72620eca6..dacd5978c1 100644 --- a/src/inc/tfs.h +++ b/src/inc/tfs.h @@ -63,7 +63,7 @@ typedef struct { #define TFILE_NAME(pf) ((pf)->aname) #define TFILE_REL_NAME(pf) ((pf)->rname) -#define tfsopen(pf, flags) open(TFILE_NAME(pf), flags) +#define tfsopen(pf, flags) open(TFILE_NAME(pf), flags | O_BINARY) #define tfsclose(fd) close(fd) #define tfsremove(pf) remove(TFILE_NAME(pf)) #define tfscopy(sf, df) taosCopy(TFILE_NAME(sf), TFILE_NAME(df)) diff --git a/src/os/src/detail/osRand.c b/src/os/src/detail/osRand.c index 0dda908bb3..e1d81ea5d3 100644 --- a/src/os/src/detail/osRand.c +++ b/src/os/src/detail/osRand.c @@ -22,7 +22,7 @@ uint32_t taosSafeRand(void) { int fd; int seed; - fd = open("/dev/urandom", 0); + fd = open("/dev/urandom", 0 | O_BINARY); if (fd < 0) { seed = (int)time(0); } else { diff --git a/src/os/src/detail/osSysinfo.c b/src/os/src/detail/osSysinfo.c index 8f39459f2e..8412e0f3d4 100644 --- a/src/os/src/detail/osSysinfo.c +++ b/src/os/src/detail/osSysinfo.c @@ -652,7 +652,7 @@ bool taosGetSystemUid(char *uid) { int fd; int len = 0; - fd = open("/proc/sys/kernel/random/uuid", 0); + fd = open("/proc/sys/kernel/random/uuid", 0 | O_BINARY); if (fd < 0) { return false; } else { diff --git a/src/os/src/linux/linuxEnv.c b/src/os/src/linux/linuxEnv.c index e31364e222..1dc7abb13a 100644 --- a/src/os/src/linux/linuxEnv.c +++ b/src/os/src/linux/linuxEnv.c @@ -35,7 +35,7 @@ char* taosGetCmdlineByPID(int pid) { static char cmdline[1024]; sprintf(cmdline, "/proc/%d/cmdline", pid); - int fd = open(cmdline, O_RDONLY); + int fd = open(cmdline, O_RDONLY | O_BINARY); if (fd >= 0) { int n = read(fd, cmdline, sizeof(cmdline) - 1); if (n < 0) n = 0; diff --git a/src/rpc/test/rserver.c b/src/rpc/test/rserver.c index e9c5fc47b8..05f328a6fc 100644 --- a/src/rpc/test/rserver.c +++ b/src/rpc/test/rserver.c @@ -172,7 +172,7 @@ int main(int argc, char *argv[]) { tInfo("RPC server is running, ctrl-c to exit"); if (commit) { - dataFd = open(dataName, O_APPEND | O_CREAT | O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO); + dataFd = open(dataName, O_APPEND | O_CREAT | O_WRONLY | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO); if (dataFd<0) tInfo("failed to open data file, reason:%s", strerror(errno)); } diff --git a/src/sync/test/syncServer.c b/src/sync/test/syncServer.c index a9d9af6667..82892d6e75 100644 --- a/src/sync/test/syncServer.c +++ b/src/sync/test/syncServer.c @@ -43,7 +43,7 @@ int writeIntoWal(SWalHead *pHead) { char walName[280]; snprintf(walName, sizeof(walName), "%s/wal/wal.%d", path, walNum); (void)remove(walName); - dataFd = open(walName, O_CREAT | O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO); + dataFd = open(walName, O_CREAT | O_WRONLY | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO); if (dataFd < 0) { uInfo("failed to open wal file:%s(%s)", walName, strerror(errno)); return -1; diff --git a/src/tsdb/inc/tsdbFile.h b/src/tsdb/inc/tsdbFile.h index b9d5431de6..2bbe9444cb 100644 --- a/src/tsdb/inc/tsdbFile.h +++ b/src/tsdb/inc/tsdbFile.h @@ -75,7 +75,7 @@ static FORCE_INLINE void tsdbSetMFileInfo(SMFile* pMFile, SMFInfo* pInfo) { pMFi static FORCE_INLINE int tsdbOpenMFile(SMFile* pMFile, int flags) { ASSERT(TSDB_FILE_CLOSED(pMFile)); - pMFile->fd = open(TSDB_FILE_FULL_NAME(pMFile), flags); + pMFile->fd = open(TSDB_FILE_FULL_NAME(pMFile), flags | O_BINARY); if (pMFile->fd < 0) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; @@ -189,7 +189,7 @@ static FORCE_INLINE void tsdbSetDFileInfo(SDFile* pDFile, SDFInfo* pInfo) { pDFi static FORCE_INLINE int tsdbOpenDFile(SDFile* pDFile, int flags) { ASSERT(!TSDB_FILE_OPENED(pDFile)); - pDFile->fd = open(TSDB_FILE_FULL_NAME(pDFile), flags); + pDFile->fd = open(TSDB_FILE_FULL_NAME(pDFile), flags | O_BINARY); if (pDFile->fd < 0) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index 567402f3ed..a5ef86ee5a 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -179,7 +179,7 @@ static void *taosThreadToOpenNewFile(void *param) { umask(0); - int32_t fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); + int32_t fd = open(name, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO); if (fd < 0) { tsLogObj.openInProgress = 0; tsLogObj.lines = tsLogObj.maxLines - 1000; @@ -240,7 +240,7 @@ void taosResetLog() { } static bool taosCheckFileIsOpen(char *logFileName) { - int32_t fd = open(logFileName, O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO); + int32_t fd = open(logFileName, O_WRONLY | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO); if (fd < 0) { if (errno == ENOENT) { return false; @@ -328,7 +328,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) { pthread_mutex_init(&tsLogObj.logMutex, NULL); umask(0); - tsLogObj.logHandle->fd = open(fileName, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); + tsLogObj.logHandle->fd = open(fileName, O_WRONLY | O_CREAT | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO); if (tsLogObj.logHandle->fd < 0) { printf("\nfailed to open log file:%s, reason:%s\n", fileName, strerror(errno)); diff --git a/src/util/src/tnote.c b/src/util/src/tnote.c index b691abc5b9..193ad3263c 100644 --- a/src/util/src/tnote.c +++ b/src/util/src/tnote.c @@ -92,7 +92,7 @@ static void *taosThreadToOpenNewNote(void *param) { umask(0); - int32_t fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); + int32_t fd = open(name, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO); if (fd < 0) { return NULL; } @@ -132,7 +132,7 @@ static int32_t taosOpenNewNote(SNoteObj *pNote) { } static bool taosCheckNoteIsOpen(char *noteName, SNoteObj *pNote) { - int32_t fd = open(noteName, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); + int32_t fd = open(noteName, O_WRONLY | O_CREAT | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO); if (fd < 0) { fprintf(stderr, "failed to open note:%s reason:%s\n", noteName, strerror(errno)); return true; @@ -207,7 +207,7 @@ static int32_t taosOpenNoteWithMaxLines(char *fn, int32_t maxLines, int32_t maxN pthread_mutex_init(&pNote->mutex, NULL); umask(0); - pNote->fd = open(noteName, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); + pNote->fd = open(noteName, O_WRONLY | O_CREAT | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO); if (pNote->fd < 0) { fprintf(stderr, "failed to open note file:%s reason:%s\n", noteName, strerror(errno)); -- GitLab