about summary refs log tree commit diff
path: root/sysdeps/posix/spawni.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/posix/spawni.c')
-rw-r--r--sysdeps/posix/spawni.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/sysdeps/posix/spawni.c b/sysdeps/posix/spawni.c
index 483dc2681d..631a1798f6 100644
--- a/sysdeps/posix/spawni.c
+++ b/sysdeps/posix/spawni.c
@@ -204,9 +204,21 @@ __spawni_child (void *arguments)
 	      break;
 
 	    case spawn_do_dup2:
-	      if (__dup2 (action->action.dup2_action.fd,
-			  action->action.dup2_action.newfd)
-		  != action->action.dup2_action.newfd)
+	      /* Austin Group issue #411 requires adddup2 action with source
+		 and destination being equal to remove close-on-exec flag.  */
+	      if (action->action.dup2_action.fd
+		  == action->action.dup2_action.newfd)
+		{
+		  int fd = action->action.dup2_action.newfd;
+		  int flags = __fcntl (fd, F_GETFD, 0);
+		  if (flags == -1)
+		    goto fail;
+		  if (__fcntl (fd, F_SETFD, flags & ~FD_CLOEXEC) == -1)
+		    goto fail;
+		}
+	      else if (__dup2 (action->action.dup2_action.fd,
+			       action->action.dup2_action.newfd)
+		       != action->action.dup2_action.newfd)
 		goto fail;
 	      break;