aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/fd_util.c10
-rw-r--r--src/fd_util.h7
2 files changed, 17 insertions, 0 deletions
diff --git a/src/fd_util.c b/src/fd_util.c
index b9443b03d..769823bc4 100644
--- a/src/fd_util.c
+++ b/src/fd_util.c
@@ -104,6 +104,16 @@ fd_set_nonblock(int fd)
}
int
+dup_cloexec(int oldfd)
+{
+ int newfd = dup(oldfd);
+ if (newfd >= 0)
+ fd_set_nonblock(newfd);
+
+ return newfd;
+}
+
+int
open_cloexec(const char *path_fs, int flags, int mode)
{
int fd;
diff --git a/src/fd_util.h b/src/fd_util.h
index 80fb98703..5b80df2c7 100644
--- a/src/fd_util.h
+++ b/src/fd_util.h
@@ -50,6 +50,13 @@
struct sockaddr;
/**
+ * Wrapper for dup(), which sets the CLOEXEC flag on the new
+ * descriptor.
+ */
+int
+dup_cloexec(int oldfd);
+
+/**
* Wrapper for open(), which sets the CLOEXEC flag (atomically if
* supported by the OS).
*/