From 6343da070e8e49eddde7904d6852c285f5147dbf Mon Sep 17 00:00:00 2001 From: zhaifenghw Date: Mon, 13 Sep 2021 07:17:14 +0000 Subject: [PATCH] fix mac building issues Signed-off-by: zhaifenghw --- src/common/base.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/common/base.cpp b/src/common/base.cpp index cd58b388..6d63eab0 100644 --- a/src/common/base.cpp +++ b/src/common/base.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #ifdef __MUSL__ extern "C" { #include "parameter.h" @@ -41,20 +42,14 @@ namespace Base { #ifdef ENABLE_DEBUGLOG void GetLogDebugFunctioname(string &debugInfo, int line, string &threadIdString) { - uint32_t currentThreadId = 0; string tmpString = GetFileNameAny(debugInfo); -#ifdef _WIN32 - currentThreadId = GetCurrentThreadId(); -#else - currentThreadId = uv_thread_self(); // 64bit OS, just dispaly 32bit ptr -#endif debugInfo = StringFormat("%s:%d", tmpString.c_str(), line); if (g_logLevel < LOG_FULL) { debugInfo = ""; threadIdString = ""; } else { debugInfo = "[" + debugInfo + "]"; - threadIdString = StringFormat("[%x]", currentThreadId); + threadIdString = StringFormat("[%x]", std::hash{}(std::this_thread::get_id())); } } @@ -800,7 +795,22 @@ namespace Base { int CreateSocketPair(int *fds) { #ifndef _WIN32 +#ifdef HOST_MAC + int ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds); + if (ret == 0) { + for (auto i = 0; i < 2; ++i) { + if (fcntl(fds[i], F_SETFD, FD_CLOEXEC) == -1) { + close(fds[0]); + close(fds[1]); + WRITE_LOG(LOG_WARN, "fcntl failed to set FD_CLOEXEC: %s", strerror(errno)); + return -1; + } + } + } + return ret; +#else return socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fds); +#endif #else struct sockaddr_in addr; socklen_t addrlen = sizeof(addr); -- Gitee