glibc/sysdeps/unix/sysv/linux/sh
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
..
be posix: Add terminal control setting support for posix_spawn 2022-01-25 14:07:53 -03:00
bits Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
le posix: Add terminal control setting support for posix_spawn 2022-01-25 14:07:53 -03:00
sh3 Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
sh4 Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
sys Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
Implies
Makefile
Versions Add libc ABI extension kludge for baseline-violating libdl symbols 2021-06-02 07:34:24 +02:00
____longjmp_chk.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
adaptive_spin_count.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
arch-syscall.h Update syscall lists for Linux 5.16 2022-01-13 22:18:13 +00:00
atomic-machine.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
c++-types.data
clone.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
configure
configure.ac
fanotify_mark.c linux: Add fanotify_mark C implementation 2021-11-25 09:56:57 -03:00
kernel-features.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
kernel_sigaction.h m68k: Fix sigaction kernel definition (BZ #23960) 2018-12-18 16:45:10 -02:00
kernel_stat.h linux: Set default kernel_stat.h to LFS 2021-02-11 07:58:05 -03:00
localplt.data mtrace: Wean away from malloc hooks 2021-07-22 18:38:06 +05:30
lowlevel-atomic.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
makecontext.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
shlib-versions Move malloc hooks into a compat DSO 2021-07-22 18:37:59 +05:30
sigaltstack-offsets.sym
sigcontextinfo.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
syscall.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
syscalls.list linux: Add prlimit64 C implementation 2021-11-30 13:13:03 -03:00
sysdep.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
sysdep.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
time64-compat.h y2038: Add support for 64-bit time on legacy ABIs 2021-06-15 10:42:11 -03:00
vfork.S Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00