From 09f670cd1403b3315a0119910d838c8e6fc031f9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 20 Oct 2010 13:12:00 +0000 Subject: [PATCH] fix setting close on exec --- src/util/disk.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/util/disk.c b/src/util/disk.c index 65509166e..265295922 100644 --- a/src/util/disk.c +++ b/src/util/disk.c @@ -1642,6 +1642,7 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h) #endif } + /** * Creates an interprocess channel * @@ -1672,24 +1673,34 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write) ret = pipe (fd); if (ret == -1) { + eno = errno; + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe"); GNUNET_free (p); + errno = eno; return NULL; } p->fd[0]->fd = fd[0]; p->fd[1]->fd = fd[1]; ret = 0; flags = fcntl (fd[0], F_GETFL); - flags |= FD_CLOEXEC; if (!blocking) flags |= O_NONBLOCK; if (0 > fcntl (fd[0], F_SETFL, flags)) ret = -1; - flags = fcntl (fd[1], F_GETFL); + flags = fcntl (fd[0], F_GETFD); flags |= FD_CLOEXEC; + if (0 > fcntl (fd[0], F_SETFD, flags)) + ret = -1; + + flags = fcntl (fd[1], F_GETFL); if (!blocking) flags |= O_NONBLOCK; if (0 > fcntl (fd[1], F_SETFL, flags)) ret = -1; + flags = fcntl (fd[1], F_GETFD); + flags |= FD_CLOEXEC; + if (0 > fcntl (fd[1], F_SETFD, flags)) + ret = -1; if (ret == -1) { eno = errno; -- 2.25.1