From d09bc715a39c5f78c213c73cf98b8ef24a84a1ab Mon Sep 17 00:00:00 2001 From: "Sergey V. Lobanov" Date: Tue, 23 Aug 2022 00:40:16 +0300 Subject: accel-cmd: add macos compatibility MacOS socket does not support SOCK_CLOEXEC. This patch uses fcntl with FD_CLOEXEC instead of using SOCK_CLOEXEC in socket() call Signed-off-by: Sergey V. Lobanov --- accel-cmd/accel_cmd.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/accel-cmd/accel_cmd.c b/accel-cmd/accel_cmd.c index 273a2dd..3de8624 100644 --- a/accel-cmd/accel_cmd.c +++ b/accel-cmd/accel_cmd.c @@ -480,7 +480,7 @@ static int accel_connect(struct host_params *peer, bool numeric) for (ai = res; ai; ai = ai->ai_next) { fd = socket(ai->ai_family, - ai->ai_socktype | SOCK_CLOEXEC, + ai->ai_socktype, ai->ai_protocol); if (fd < 0) { fverbf(stderr, "%s,%i:" @@ -488,10 +488,18 @@ static int accel_connect(struct host_params *peer, bool numeric) " socket() failed: %s\n", __func__, __LINE__, ai->ai_family, - ai->ai_socktype | SOCK_CLOEXEC, + ai->ai_socktype, ai->ai_protocol, strerror(errno)); continue; } + int ret = fcntl(fd, F_SETFD, FD_CLOEXEC); + if (ret == -1) { + fverbf(stderr, "%s,%i:" + " fcntl() failed on setting FD_CLOEXEC: %s\n", + __func__, __LINE__, + strerror(errno)); + continue; + } if (connect(fd, ai->ai_addr, ai->ai_addrlen) < 0) { fverbf(stderr, "%s,%i: connect() failed: %s\n", __func__, __LINE__, strerror(errno)); -- cgit v1.2.3