aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGilles Chehade <gilles@poolp.org>2020-05-06 00:06:42 +0200
committerGilles Chehade <gilles@poolp.org>2020-05-06 00:06:42 +0200
commit4d36e58bdbd942beeefb4650dd2929802935e6c1 (patch)
tree638995aa124f1727260a5903cbb0affecb42653f
parentreorder (diff)
downloadOpenSMTPD-4d36e58bdbd942beeefb4650dd2929802935e6c1.tar.xz
OpenSMTPD-4d36e58bdbd942beeefb4650dd2929802935e6c1.zip
add pipe2() compat layer, fixes build on OSX
-rw-r--r--configure.ac2
-rw-r--r--openbsd-compat/Makefile.am4
-rw-r--r--openbsd-compat/pipe2.c36
3 files changed, 42 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 33b929c1..28f1be1f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -587,6 +587,7 @@ AC_CHECK_FUNCS([ \
memmove \
nanosleep \
nsleep \
+ pipe2 \
pidfile \
pledge \
reallocarray \
@@ -2014,6 +2015,7 @@ AM_CONDITIONAL([NEED_GETOPT], [test "x$ac_cv_func_getopt" != "xyes"])
AM_CONDITIONAL([NEED_GETPEEREID], [test "x$ac_cv_func_getpeereid" != "xyes"])
AM_CONDITIONAL([NEED_NANOSLEEP], [test "x$ac_cv_func_nanosleep" != "xyes"])
AM_CONDITIONAL([NEED_PIDFILE], [test "x$ac_cv_func_pidfile" != "xyes"])
+AM_CONDITIONAL([NEED_PIPE2], [test "x$ac_cv_func_pipe2" != "xyes"])
AM_CONDITIONAL([NEED_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" != "xyes"])
AM_CONDITIONAL([NEED_RECALLOCARRAY], [test "x$ac_cv_func_recallocarray" != "xyes"])
AM_CONDITIONAL([NEED_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" != "xyes"])
diff --git a/openbsd-compat/Makefile.am b/openbsd-compat/Makefile.am
index db1e93fa..f5d9a02e 100644
--- a/openbsd-compat/Makefile.am
+++ b/openbsd-compat/Makefile.am
@@ -116,6 +116,10 @@ if NEED_PIDFILE
libopenbsd_a_SOURCES += pidfile.c
endif
+if NEED_PIPE2
+libopenbsd_a_SOURCES += pipe2.c
+endif
+
if NEED_REALLOCARRAY
libopenbsd_a_SOURCES += reallocarray.c
endif
diff --git a/openbsd-compat/pipe2.c b/openbsd-compat/pipe2.c
new file mode 100644
index 00000000..710f8df2
--- /dev/null
+++ b/openbsd-compat/pipe2.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2020 Gilles Chehade <gilles@poolp.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "includes.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+
+int
+pipe2(int pipefd[2], int flags)
+{
+ if (pipe(pipefd) == -1)
+ return -1;
+
+ if (fcntl(pipefd[0], F_SETFL, FD_CLOEXEC) == -1 ||
+ fcntl(pipefd[1], F_SETFL, FD_CLOEXEC) == -1) {
+ close(pipefd[0]);
+ close(pipefd[1]);
+ return -1;
+ }
+
+ return 0;
+}