diff --git a/src/common/base.cpp b/src/common/base.cpp index cd58b388bb0c4fdfdff00cdbd7afd0d698b53945..6d63eab04072349ff0ccb224a92cacc925f9a088 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);