From cbe30fb952fb35df815e97b5397eb3f912866ad4 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 14 Apr 2020 16:12:17 -0700 Subject: [PATCH] macOS build fix: no SOCK_CLOEXEC on darwin. We can't use the sysdeps.h copy of this code, so for now add yet another copy & paste. We should come up with something better in libbase, but let's get the macOS build fixed first. Test: builds on mac Change-Id: Ifb059990d7091f3d91b54e684f4ee14afe69c28b --- adb/libs/adbconnection/adbconnection_client.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/adb/libs/adbconnection/adbconnection_client.cpp b/adb/libs/adbconnection/adbconnection_client.cpp index c13234218..b569421db 100644 --- a/adb/libs/adbconnection/adbconnection_client.cpp +++ b/adb/libs/adbconnection/adbconnection_client.cpp @@ -122,7 +122,16 @@ AdbConnectionClientContext* adbconnection_client_new( return nullptr; } +#if defined(__APPLE__) + ctx->control_socket_.reset(socket(AF_UNIX, SOCK_SEQPACKET, 0)); + // TODO: find a better home for all these copies of the mac CLOEXEC workaround. + if (int fd = ctx->control_socket_.get(), flags = fcntl(fd, F_GETFD); + flags != -1 && (flags & FD_CLOEXEC) == 0) { + fcntl(fd, F_SETFD, flags | FD_CLOEXEC); + } +#else ctx->control_socket_.reset(socket(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0)); +#endif if (ctx->control_socket_ < 0) { PLOG(ERROR) << "failed to create Unix domain socket"; return nullptr;