From 651a4c6f7f98728a57b7b2e6746108b6e4b0967b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Wed, 20 Sep 2023 14:17:08 -0400
Subject: [PATCH] dsh: support macOS for pipe()

Change-Id: If2dbf456f0f2dbc7f04e1dec4db7986ad10f6f54
---
 tools/dsh/dsh.cpp | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/tools/dsh/dsh.cpp b/tools/dsh/dsh.cpp
index cd9df82..51b80a5 100644
--- a/tools/dsh/dsh.cpp
+++ b/tools/dsh/dsh.cpp
@@ -28,13 +28,25 @@ const int READ_END = 0;
 const int WRITE_END = 1;
 
 void
-create_pipe(int pipe[2])
+create_pipe(int apipe[2])
 {
-    if (pipe2(pipe, O_CLOEXEC) == -1) {
+#ifdef __APPLE__
+    if (pipe(apipe) < 0)
+        perror("pipe");
+
+    if (fcntl(apipe[0], F_SETFD, FD_CLOEXEC) < 0)
+        perror("unable to set pipe FD_CLOEXEC");
+
+    if (fcntl(apipe[1], F_SETFD, FD_CLOEXEC) < 0)
+        perror("unable to set pipe FD_CLOEXEC");
+#else
+    if (pipe2(apipe, O_CLOEXEC) == -1) {
         perror("pipe2");
         exit(EXIT_FAILURE);
     }
+#endif
 }
+
 void
 child_proc(const int in_pipe[2],
            const int out_pipe[2],
-- 
GitLab