summaryrefslogtreecommitdiff
path: root/accel-cmd
diff options
context:
space:
mode:
authorSergey V. Lobanov <sergey@lobanov.in>2022-08-23 00:40:16 +0300
committerSergey V. Lobanov <sergey@lobanov.in>2022-08-23 00:40:16 +0300
commitd09bc715a39c5f78c213c73cf98b8ef24a84a1ab (patch)
treea2fdc4379fbb71bcf843570af2c1a798c0c441db /accel-cmd
parent34de38532c85fb7b61412e6dae58794bd93977f5 (diff)
downloadaccel-ppp-d09bc715a39c5f78c213c73cf98b8ef24a84a1ab.tar.gz
accel-ppp-d09bc715a39c5f78c213c73cf98b8ef24a84a1ab.zip
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 <sergey@lobanov.in>
Diffstat (limited to 'accel-cmd')
-rw-r--r--accel-cmd/accel_cmd.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/accel-cmd/accel_cmd.c b/accel-cmd/accel_cmd.c
index 273a2dda..3de8624f 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));