glibc/sysdeps
Adhemerval Zanella 342cc934a3 posix: Add terminal control setting support for posix_spawn
Currently there is no proper way to set the controlling terminal through
posix_spawn in race free manner [1].  This forces shell implementations
to keep using fork+exec when launching background process groups,
even when using posix_spawn yields better performance.

This patch adds a new GNU extension so the creating process can
configure the created process terminal group.  This is done with a new
flag, POSIX_SPAWN_TCSETPGROUP, along with two new attribute functions:
posix_spawnattr_tcsetpgrp_np, and posix_spawnattr_tcgetpgrp_np.
The function sets a new attribute, spawn-tcgroupfd, that references to
the controlling terminal.

The controlling terminal is set after the spawn-pgroup attribute, and
uses the spawn-tcgroupfd along with current creating process group
(so it is composable with POSIX_SPAWN_SETPGROUP).

To create a process and set the controlling terminal, one can use the
following sequence:

    posix_spawnattr_t attr;
    posix_spawnattr_init (&attr);
    posix_spawnattr_setflags (&attr, POSIX_SPAWN_TCSETPGROUP);
    posix_spawnattr_tcsetpgrp_np (&attr, tcfd);

If the idea is also to create a new process groups:

    posix_spawnattr_t attr;
    posix_spawnattr_init (&attr);
    posix_spawnattr_setflags (&attr, POSIX_SPAWN_TCSETPGROUP
				     | POSIX_SPAWN_SETPGROUP);
    posix_spawnattr_tcsetpgrp_np (&attr, tcfd);
    posix_spawnattr_setpgroup (&attr, 0);

The controlling terminal file descriptor is ignored if the new flag is
not set.

This interface is slight different than the one provided by QNX [2],
which only provides the POSIX_SPAWN_TCSETPGROUP flag.  The QNX
documentation does not specify how the controlling terminal is obtained
nor how it iteracts with POSIX_SPAWN_SETPGROUP.  Since a glibc
implementation is library based, it is more straightforward and avoid
requires additional file descriptor operations to request the caller
to setup the controlling terminal file descriptor (and it also allows
a bit less error handling by posix_spawn).

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

[1] https://github.com/ksh93/ksh/issues/79
[2] https://www.qnx.com/developers/docs/7.0.0/index.html#com.qnx.doc.neutrino.lib_ref/topic/p/posix_spawn.html

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
2022-01-25 14:07:53 -03:00
..
aarch64 AArch64: Check for SVE in ifuncs [BZ #28744] 2022-01-06 14:36:28 +00:00
alpha Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
arc Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
arm Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
csky Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
generic elf: Fix 64 time_t support for installed statically binaries 2022-01-17 10:57:09 -03:00
gnu Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
hppa Restore ENTRY_POINT definition on hppa, ia64 (bug 28749) 2022-01-07 14:47:31 +01:00
htl htl: Fix build error in annexc 2022-01-17 23:18:27 +00:00
hurd hurd: Fix pthread_kill on exiting/ted thread 2022-01-15 15:11:54 +01:00
i386 Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
ia64 Restore ENTRY_POINT definition on hppa, ia64 (bug 28749) 2022-01-07 14:47:31 +01:00
ieee754 math: Fix float conversion regressions with gcc-12 [BZ #28713] 2022-01-10 14:27:17 +00:00
m68k Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
mach posix: Add terminal control setting support for posix_spawn 2022-01-25 14:07:53 -03:00
microblaze Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
mips mips: Move DT_MIPS into <ldsodefs.h> 2022-01-19 20:11:55 +01:00
nios2 Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
nptl Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
or1k or1k: Build Infrastructure 2022-01-05 06:40:06 +09:00
posix getcwd: Set errno to ERANGE for size == 1 (CVE-2021-3999) 2022-01-24 11:00:17 +05:30
powerpc powerpc64le: Use <gcc-macros.h> in early HWCAP check 2022-01-14 20:17:40 +01:00
pthread Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
riscv Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
s390 s390x: Use <gcc-macros.h> in early HWCAP check 2022-01-14 20:17:58 +01:00
sh Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
sparc Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
unix posix: Add terminal control setting support for posix_spawn 2022-01-25 14:07:53 -03:00
wordsize-32 Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
wordsize-64 Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
x86 x86: Black list more Intel CPUs for TSX [BZ #27398] 2022-01-18 14:20:09 -08:00
x86_64 math: Add more inputs to atan2 accuracy tests [BZ #28765] 2022-01-14 06:00:06 -08:00