aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGilles Chehade <gilles@poolp.org>2020-05-24 14:46:59 +0200
committerGitHub <noreply@github.com>2020-05-24 14:46:59 +0200
commit726ef4b255331806af45caa8cc7e781cbcb01aab (patch)
tree5d653c3620b665ff9b99e2f3d3e73f12d4041461
parentportable -> master (diff)
parentcompat: pipe2: enable O_CLOEXEC correctly and support O_NONBLOCK (diff)
downloadOpenSMTPD-726ef4b255331806af45caa8cc7e781cbcb01aab.tar.xz
OpenSMTPD-726ef4b255331806af45caa8cc7e781cbcb01aab.zip
Merge pull request #1063 from zx2c4-forks/jd/pipe2flags
compat: pass flags argument to pipe2
-rw-r--r--openbsd-compat/pipe2.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/openbsd-compat/pipe2.c b/openbsd-compat/pipe2.c
index 710f8df2..fd5c3f49 100644
--- a/openbsd-compat/pipe2.c
+++ b/openbsd-compat/pipe2.c
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2020 Gilles Chehade <gilles@poolp.org>
+ * Copyright (C) 2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -25,12 +26,21 @@ 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;
- }
+ if ((flags & O_NONBLOCK) &&
+ (fcntl(pipefd[0], F_SETFL, O_NONBLOCK) == -1 ||
+ fcntl(pipefd[1], F_SETFL, O_NONBLOCK) == -1)) {
+ close(pipefd[0]);
+ close(pipefd[1]);
+ return -1;
+ }
+
+ if ((flags & O_CLOEXEC) &&
+ (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) == -1 ||
+ fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) == -1)) {
+ close(pipefd[0]);
+ close(pipefd[1]);
+ return -1;
+ }
return 0;
}