glibc/include
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
..
arpa resolv: Move ns_samename into its own file, and into libc 2021-07-19 07:56:21 +02:00
bits Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
gnu Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
net
netinet
programs Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
protocols
rpc Handle out-of-memory case in svc_tcp.c/svc_unix.c:rendezvous_request. 2020-12-10 11:11:20 +01:00
rpcsvc
sys Linux: Add epoll_pwait2 (BZ #27359) 2022-01-17 14:34:54 -03:00
aio.h Linux: Move aio_suspend, aio_suspend64, __aio_suspend_time64 to libc 2021-06-25 11:55:27 +02:00
aliases.h
alloc_buffer.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
alloca.h
allocate_once.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
ar.h
argp-fmtstream.h
argp.h
argz.h
array_length.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
assert.h
atomic_wide_counter.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
atomic.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
byteswap.h
clone_internal.h Add an internal wrapper for clone, clone2 and clone3 2021-07-14 06:33:58 -07:00
complex.h
cpio.h
crypt.h
ctype.h
des.h
dirent.h Use 64 bit time_t stat internally 2021-06-22 12:09:52 -03:00
dlfcn.h elf: Add _dl_find_object function 2021-12-28 22:52:56 +01:00
dso_handle.h
elf.h
endian.h
envz.h
err.h
errno.h Remove tls.h inclusion from internal errno.h 2020-11-13 12:59:19 -03:00
error.h
execinfo.h
fcntl.h
features-time64.h y2038: Add support for 64-bit time on legacy ABIs 2021-06-15 10:42:11 -03:00
features.h Enable _FORTIFY_SOURCE=3 for gcc 12 and above 2022-01-12 18:46:28 +05:30
fenv.h
file_change_detection.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
filename.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
float.h
fmtmsg.h
fnmatch.h
fpu_control.h
fstab.h
fts.h io: Add fts64 with 64-bit time_t support 2021-06-15 10:42:11 -03:00
ftw.h io: Add ftw64 with 64-bit time_t support 2021-06-15 10:42:11 -03:00
gconv.h
getopt_int.h
getopt.h
glob.h Fix extra PLT reference in libc.so due to __glob64_time64 if build with gcc 7.5 on 32bit. 2021-07-01 16:46:59 +02:00
gmp.h
gnu-versions.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
grp-merge.h
grp.h
gshadow.h
iconv.h
idx.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
ifaddrs.h
ifreq.h
ifunc-impl-list.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
inline-hashtab.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
intprops.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
inttypes.h Make strtoimax, strtoumax, wcstoimax, wcstoumax into aliases 2020-12-08 18:15:27 +00:00
langinfo.h
lastlog.h
libc-diag.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
libc-internal.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
libc-pointer-arith.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
libc-symbols.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
libgen.h
libintl.h
limits.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
link.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
list_t.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
list.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
locale.h
loop_unroll.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
malloc.h Simplify __malloc_initialized 2021-07-22 18:38:04 +05:30
math-narrow-eval.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
math.h Redirect fma calls to __fma in libm 2021-09-15 22:57:35 +00:00
mcheck.h mcheck: Wean away from malloc hooks [BZ #23489] 2021-07-22 18:38:02 +05:30
memory.h
mntent.h
monetary.h
mqueue.h Linux: Move mq_send, mq_timedsend, __mq_timedsend_time64 to libc 2021-06-25 12:21:12 +02:00
netdb.h nss_files: Move into libc 2021-07-07 18:33:52 +02:00
netgroup.h
nl_types.h
nss_dns.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
nss_files.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
nss.h
nsswitch.h
obstack.h
plural-exp.h
poll.h
printf.h
pthread.h Linux: Move mq_notify from librt to libc 2021-06-25 12:20:47 +02:00
pty.h login: Move libutil into libc 2021-06-30 08:43:37 +02:00
pwd.h
random-bits.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
re_comp.h
regex.h regex: copy back from Gnulib 2021-09-21 08:00:44 -07:00
regexp.h
register-atfork.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
resolv.h resolv: Move res_queriesmatch to its own file and into libc 2021-07-19 07:56:21 +02:00
rounding-mode.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
rtld-malloc.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
sched.h
scratch_buffer.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
search.h
set-hooks.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
setjmp.h setjmp: Replace jmp_buf-macros.h with jmp_buf-macros.sym 2021-11-22 13:43:22 -03:00
sgtty.h
shadow.h
shlib-compat.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
shm-directory.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
signal.h hurd: keep only required PLTs in ld.so 2020-11-11 02:36:22 +01:00
spawn.h
stab.h
stackinfo.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
stap-probe.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
stdc-predef.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
stdint.h
stdio_ext.h
stdio.h libio: Replace internal _IO_getdelim symbol with __getdelim 2021-07-07 18:33:52 +02:00
stdlib.h Remove __morecore and __default_morecore 2021-07-22 18:37:57 +05:30
string.h String: Add hidden defs for __memcmpeq() to enable internal usage 2021-10-26 16:51:29 -05:00
strings.h
struct___timeb64.h time: Add 64-bit time_t support for ftime 2020-10-27 09:54:50 -03:00
struct___timespec64.h
struct___timeval64.h
stubs-prologue.h
syscall.h
sysexits.h
syslog.h
tar.h
termios.h
tgmath.h
time.h time: Fix overflow itimer tests on 32-bit systems 2021-08-15 07:09:58 +09:00
ttyent.h
uchar.h
ucontext.h
ulimit.h
unistd.h posix: Add terminal control setting support for posix_spawn 2022-01-25 14:07:53 -03:00
utime.h
utmp.h login: Move libutil into libc 2021-06-30 08:43:37 +02:00
values.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
verify.h
wait.h
wchar.h
wctype.h
wordexp.h