git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] set FD_CLOEXEC properly when O_CLOEXEC is not supported
@ 2017-07-15 18:55 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2017-07-15 18:55 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

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>
---
 sha1_file.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index fca165f13c..b60ae15f70 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1684,14 +1684,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;
 		}
 	}
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2017-07-15 18:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-15 18:55 [PATCH] set FD_CLOEXEC properly when O_CLOEXEC is not supported Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).