]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
hurd: Respect existing FD_CLOEXEC in S_msg_set_fd
authorSergey Bugaev <bugaevc@gmail.com>
Sat, 29 Apr 2023 13:13:53 +0000 (16:13 +0300)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sat, 29 Apr 2023 14:57:04 +0000 (16:57 +0200)
If the process has set the close-on-exec flag for the file descriptor,
it expects the file descriptor to get closed on exec, even if we replace
what the file descriptor refers to.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-Id: <20230429131354.2507443-6-bugaevc@gmail.com>

hurd/hurdmsg.c

index 896fb87cfa79cce12a5bf7f960efec3b36128a17..8fde1f535d10d182d0c5f2d8e1c9891531577e64 100644 (file)
@@ -323,7 +323,13 @@ _S_msg_set_fd (mach_port_t msgport, mach_port_t auth,
   AUTHCHECK;
 
   /* We consume the reference if successful.  */
-  err = HURD_FD_USE (which, (_hurd_port2fd (descriptor, port, 0), 0));
+  err = HURD_FD_USE (which,
+                    ({
+                      int flags = (descriptor->flags & FD_CLOEXEC)
+                                  ? O_CLOEXEC : 0;
+                      _hurd_port2fd (descriptor, port, flags);
+                      0;
+                    }));
   if (err)
     return err;