git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] set FD_CLOEXEC properly when O_CLOEXEC is not supported

From
EWEric Wong <e@80x24.org>
Date
Jul 15, 2017, 18:55 UTC
Message-ID
<20170715185540.6778-1-e@80x24.org>

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
Message 1 of 1 in “set FD_CLOEXEC properly when O_CLOEXEC is not supported”
  1. set FD_CLOEXEC properly when O_CLOEXEC is not supportedEric Wong, Jul 15, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.