about summary refs log tree commit diff
path: root/sysdeps/unix/sysv/linux/spawni.c
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2022-01-27 10:11:30 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2022-02-02 08:34:16 -0300
commit6289d28d3c4e56f34830cfb011c31271ef850418 (patch)
tree32d0c4d7af2c5a6a9d293a1ea05eb0d45313e450 /sysdeps/unix/sysv/linux/spawni.c
parent3f35e7d193b7ff098467996ebf85b19c41d6d86e (diff)
downloadglibc-6289d28d3c4e56f34830cfb011c31271ef850418.tar.gz
glibc-6289d28d3c4e56f34830cfb011c31271ef850418.tar.xz
glibc-6289d28d3c4e56f34830cfb011c31271ef850418.zip
posix: Replace posix_spawnattr_tc{get,set}pgrp_np with posix_spawn_file_actions_addtcsetpgrp_np
The posix_spawnattr_tcsetpgrp_np works on a file descriptor (the
controlling terminal), so it would make more sense to actually fit
it on the file actions API.

Also, POSIX_SPAWN_TCSETPGROUP is not really required since it is
implicit by the presence of tcsetpgrp file action.

The posix/tst-spawn6.c is also fixed when TTY can is not present.

Checked on x86_64-linux-gnu and i686-linux-gnu.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'sysdeps/unix/sysv/linux/spawni.c')
-rw-r--r--sysdeps/unix/sysv/linux/spawni.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/spawni.c
index 93359c708b..d703485e3f 100644
--- a/sysdeps/unix/sysv/linux/spawni.c
+++ b/sysdeps/unix/sysv/linux/spawni.c
@@ -164,17 +164,6 @@ __spawni_child (void *arguments)
       && __setpgid (0, attr->__pgrp) != 0)
     goto fail;
 
-  /* Set the controlling terminal.  */
-  if ((attr->__flags & POSIX_SPAWN_TCSETPGROUP) != 0)
-    {
-      /* Check if it is possible to avoid an extra syscall.  */
-      pid_t pgrp = (attr->__flags & POSIX_SPAWN_SETPGROUP) != 0
-		    && attr->__pgrp != 0
-		   ? attr->__pgrp : __getpgid (0);
-      if (__tcsetpgrp (attr->__ctty_fd, pgrp) != 0)
-	goto fail;
-    }
-
   /* Set the effective user and group IDs.  */
   if ((attr->__flags & POSIX_SPAWN_RESETIDS) != 0
       && (local_seteuid (__getuid ()) != 0
@@ -279,6 +268,16 @@ __spawni_child (void *arguments)
 		if (r != 0 && !__closefrom_fallback (lowfd, false))
 		  goto fail;
 	      } break;
+
+	    case spawn_do_tcsetpgrp:
+	      {
+		/* Check if it is possible to avoid an extra syscall.  */
+		pid_t pgrp = (attr->__flags & POSIX_SPAWN_SETPGROUP) != 0
+			       && attr->__pgrp != 0
+			     ? attr->__pgrp : __getpgid (0);
+		if (__tcsetpgrp (action->action.setpgrp_action.fd, pgrp) != 0)
+		  goto fail;
+	      }
 	    }
 	}
     }