From 88780e309644ef6415d2515b79ffc4060c33d701 Mon Sep 17 00:00:00 2001 From: slguan Date: Thu, 5 Sep 2019 14:36:34 +0800 Subject: [PATCH] issue #399 --- src/os/linux/inc/os.h | 2 ++ src/os/linux/src/os.c | 17 +++++++++++++++++ src/os/windows/inc/os.h | 2 ++ src/os/windows/src/twindows.c | 3 +++ src/util/src/tsocket.c | 21 +-------------------- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/os/linux/inc/os.h b/src/os/linux/inc/os.h index f1b62d147c..002d0be4ca 100644 --- a/src/os/linux/inc/os.h +++ b/src/os/linux/inc/os.h @@ -63,4 +63,6 @@ void taosGetSystemInfo(); void taosKillSystem(); +bool taosIsRunningWSLv1(); + #endif \ No newline at end of file diff --git a/src/os/linux/src/os.c b/src/os/linux/src/os.c index 7b6be057c8..d65e78e3a4 100644 --- a/src/os/linux/src/os.c +++ b/src/os/linux/src/os.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "tglobalcfg.h" #include "tlog.h" @@ -293,4 +294,20 @@ ssize_t twrite(int fd, void *buf, size_t n) { } return n; +} + +// check if the linux running is WSL +bool taosIsRunningWSLv1() { + struct utsname buf; + if (uname(&buf)) { + pPrint(" can't fetch os info"); + return false; + } + + if (strstr(buf.release, "Microsoft") != 0) { + pPrint(" using WSLv1"); + return true; + } + + return false; } \ No newline at end of file diff --git a/src/os/windows/inc/os.h b/src/os/windows/inc/os.h index 81a33141ab..7d354bf492 100644 --- a/src/os/windows/inc/os.h +++ b/src/os/windows/inc/os.h @@ -124,6 +124,8 @@ int sigaction(int, struct sigaction *, void *); void sleep(int mseconds); +bool taosIsRunningWSLv1(); + #ifdef __cplusplus } #endif diff --git a/src/os/windows/src/twindows.c b/src/os/windows/src/twindows.c index 91cc560eb9..deda1b40dc 100644 --- a/src/os/windows/src/twindows.c +++ b/src/os/windows/src/twindows.c @@ -196,4 +196,7 @@ int wordexp(const char *words, wordexp_t *pwordexp, int flags) { void wordfree(wordexp_t *pwordexp) {} void taosGetDisk() {} +bool taosIsRunningWSLv1() { + return false; +} diff --git a/src/util/src/tsocket.c b/src/util/src/tsocket.c index fe7233feec..04b59a2508 100644 --- a/src/util/src/tsocket.c +++ b/src/util/src/tsocket.c @@ -23,17 +23,14 @@ #include #include #include -#include #include "os.h" #include "tglobalcfg.h" #include "tlog.h" #include "tsocket.h" #include "tutil.h" -#include "tsystem.h" unsigned int ip2uint(const char *const ip_addr); -bool isRunningWSLv1(); /* * Function to get the public ip address of current machine. If get IP @@ -306,7 +303,7 @@ int taosOpenUdpSocket(char *ip, short port) { if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_NO_CHECK, (void *)&nocheck, sizeof(nocheck)) < 0) { // no_check is not implemented in WSL // skip the following check if system running WSLv1 - if (!isRunningWSLv1()) { + if (!taosIsRunningWSLv1()) { pError("setsockopt SO_NO_CHECK failed: %d (%s)", errno, strerror(errno)); close(sockFd); return -1; @@ -556,19 +553,3 @@ int taosCopyFds(int sfd, int dfd, int64_t len) { return 0; } - -// check if the linux running is WSL -bool isRunningWSLv1() { - struct utsname buf; - if (uname(&buf)) { - pPrint(" can't fetch os info"); - return false; - } - - if (strstr(buf.release, "Microsoft") != 0) { - pPrint(" using WSLv1"); - return true; - } - - return false; -} \ No newline at end of file -- GitLab