summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-07-15 18:55:40 +0000
committerJunio C Hamano <gitster@pobox.com>2017-07-17 14:52:16 -0700
commit9fb9495dae744098a6eb16f62b4876c87b2c773f (patch)
treebd4652321688c09f0c09aa442d88d43632c7e9fd
parent1e3001a8e2386a1433d1769a5a78007596bbc04d (diff)
downloadgit-ew/fd-cloexec-fix.tar.gz
set FD_CLOEXEC properly when O_CLOEXEC is not supportedew/fd-cloexec-fix
FD_CLOEXEC only applies to the file descriptor, so it needs to be manipuluated via F_GETFD/F_SETFD. F_GETFL/F_SETFL are for file description flags. Verified via strace with o_cloexec set to zero. Signed-off-by: Eric Wong <e@80x24.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--sha1_file.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 64e1a21fc6..5e3b6e411a 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1571,14 +1571,14 @@ int git_open_cloexec(const char *name, int flags)
fd = open(name, flags | o_cloexec);
}
-#if defined(F_GETFL) && defined(F_SETFL) && defined(FD_CLOEXEC)
+#if defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
{
static int fd_cloexec = FD_CLOEXEC;
if (!o_cloexec && 0 <= fd && fd_cloexec) {
/* Opened w/o O_CLOEXEC? try with fcntl(2) to add it */
- int flags = fcntl(fd, F_GETFL);
- if (fcntl(fd, F_SETFL, flags | fd_cloexec))
+ int flags = fcntl(fd, F_GETFD);
+ if (fcntl(fd, F_SETFD, flags | fd_cloexec))
fd_cloexec = 0;
}
}