diff options
author | Gilles Chehade <gilles@poolp.org> | 2020-05-24 14:46:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-24 14:46:59 +0200 |
commit | 726ef4b255331806af45caa8cc7e781cbcb01aab (patch) | |
tree | 5d653c3620b665ff9b99e2f3d3e73f12d4041461 | |
parent | portable -> master (diff) | |
parent | compat: pipe2: enable O_CLOEXEC correctly and support O_NONBLOCK (diff) | |
download | OpenSMTPD-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.c | 22 |
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; } |