[6/7] hurd: Respect existing FD_CLOEXEC in S_msg_set_fd

Message ID 20230429131354.2507443-6-bugaevc@gmail.com
State Committed, archived
Headers
Series [1/7] hurd: Simplify _hurd_critical_section_lock a bit |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Sergey Bugaev April 29, 2023, 1:13 p.m. UTC
  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>
---
 hurd/hurdmsg.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
  

Comments

Samuel Thibault April 29, 2023, 2:57 p.m. UTC | #1
Applied, thanks!

Sergey Bugaev, le sam. 29 avril 2023 16:13:53 +0300, a ecrit:
> 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>
> ---
>  hurd/hurdmsg.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/hurd/hurdmsg.c b/hurd/hurdmsg.c
> index 896fb87c..8fde1f53 100644
> --- a/hurd/hurdmsg.c
> +++ b/hurd/hurdmsg.c
> @@ -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;
>  
> -- 
> 2.40.1
>
  

Patch

diff --git a/hurd/hurdmsg.c b/hurd/hurdmsg.c
index 896fb87c..8fde1f53 100644
--- a/hurd/hurdmsg.c
+++ b/hurd/hurdmsg.c
@@ -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;