{"thread":{"id":"46393","subject":"[PATCH] set FD_CLOEXEC properly when O_CLOEXEC is not supported","startedAt":"2017-07-15T18:55:46Z","lastAt":"2017-07-15T18:55:46Z","messageCount":1,"participants":["Eric Wong"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"324584","messageId":"20170715185540.6778-1-e@80x24.org","threadId":"46393","inReplyTo":null,"subject":"[PATCH] set FD_CLOEXEC properly when O_CLOEXEC is not supported","fromName":"Eric Wong","fromEmail":"e@80x24.org","sentAt":"2017-07-15T18:55:40Z","receivedAt":"2017-07-15T18:55:46Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"FD_CLOEXEC only applies to the file descriptor, so it needs to be\nmanipuluated via F_GETFD/F_SETFD.  F_GETFL/F_SETFL are for file\ndescription flags.\n\nVerified via strace with o_cloexec set to zero.\n\nSigned-off-by: Eric Wong <e@80x24.org>\n---\n sha1_file.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex fca165f13c..b60ae15f70 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1684,14 +1684,14 @@ int git_open_cloexec(const char *name, int flags)\n \t\tfd = open(name, flags | o_cloexec);\n \t}\n \n-#if defined(F_GETFL) && defined(F_SETFL) && defined(FD_CLOEXEC)\n+#if defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)\n \t{\n \t\tstatic int fd_cloexec = FD_CLOEXEC;\n \n \t\tif (!o_cloexec && 0 <= fd && fd_cloexec) {\n \t\t\t/* Opened w/o O_CLOEXEC?  try with fcntl(2) to add it */\n-\t\t\tint flags = fcntl(fd, F_GETFL);\n-\t\t\tif (fcntl(fd, F_SETFL, flags | fd_cloexec))\n+\t\t\tint flags = fcntl(fd, F_GETFD);\n+\t\t\tif (fcntl(fd, F_SETFD, flags | fd_cloexec))\n \t\t\t\tfd_cloexec = 0;\n \t\t}\n \t}\n-- \nEW\n\n"}]}