glibc/sysdeps/generic
Adhemerval Zanella 882d6e17bc posix: Add posix_spawn_file_actions_addclosefrom_np
This patch adds a way to close a range of file descriptors on
posix_spawn as a new file action.  The API is similar to the one
provided by Solaris 11 [1], where the file action causes the all open
file descriptors greater than or equal to input on to be closed when
the new process is spawned.

The function posix_spawn_file_actions_addclosefrom_np is safe to be
implemented by iterating over /proc/self/fd, since the Linux spawni.c
helper process does not use CLONE_FILES, so its has own file descriptor
table and any failure (in /proc operation) aborts the process creation
and returns an error to the caller.

I am aware that this file action might be redundant to the current
approach of POSIX in promoting O_CLOEXEC in more interfaces. However
O_CLOEXEC is still not the default and for some specific usages, the
caller needs to close all possible file descriptors to avoid them
leaking.  Some examples are CPython (discussed in BZ#10353) and OpenJDK
jspawnhelper [2] (where OpenJDK spawns a helper process to exactly
closes all file descriptors).  Most likely any environment which calls
functions that might open file descriptor under the hood and aim to use
posix_spawn might face the same requirement.

Checked on x86_64-linux-gnu and i686-linux-gnu on kernel 5.11 and 4.15.

[1] https://docs.oracle.com/cd/E36784_01/html/E36874/posix-spawn-file-actions-addclosefrom-np-3c.html
[2] https://github.com/openjdk/jdk/blob/master/src/java.base/unix/native/libjava/childproc.c#L82
2021-07-08 14:08:15 -03:00
..
net
netinet
nfs
sys
Makefile
_G_config.h
_itoa.h
a.out.h
abort-instr.h
adaptive_spin_count.h
aio_misc.h Linux: Cleanups after librt move 2021-06-28 09:51:01 +02:00
allocalim.h
arch-fd_to_filename.h
asm-syntax.h
atomic-machine.h
c++-types.data
confstr.h
crti.S
crtn.S
device-nrs.h
dirstream.h
dl-auxv.h
dl-cache.h
dl-dtprocnum.h
dl-dtv.h
dl-fcntl.h
dl-fileid.h
dl-fptr.h
dl-hash.h
dl-hwcap-check.h elf: Add hook for checking HWCAP bits after auxiliary vector parsing 2021-05-19 11:09:57 +02:00
dl-irel.h
dl-isa-level.h
dl-librecon.h
dl-lookupcfg.h
dl-machine.h
dl-mman.h
dl-osinfo.h
dl-procinfo.c
dl-procinfo.h
dl-procruntime.c
dl-prop.h
dl-sysdep.h
dl-tls.h
dl-unistd.h
dl-vdso-setup.c
dl-vdso-setup.h
dl-vdso.h
dwarf2.h
elf-initfini.h
elf-read-prop.h
elf_machine_sym_no_match.h
elide.h
eloop-threshold.h
entry.h
errqueue.h
fd_to_filename.h
features-time64.h y2038: Add support for 64-bit time on legacy ABIs 2021-06-15 10:42:11 -03:00
fenv_private.h
fips-private.h
fix-fp-int-compare-invalid.h
fix-fp-int-convert-overflow.h
fix-int-fp-convert-zero.h
float128-abi.h
fork.h posix: Consolidate fork implementation 2021-06-24 10:02:06 -03:00
fpu_control.h
framestate.c
gcc-compat.h
gccframe.h
get-rounding-mode.h
gmp-mparam.h
hp-timing-common.h
hp-timing.h
ifreq.h
ifunc-init.h
ifunc-sel.h
internal-signals.h
intr-msg.h
ld.abilist
ldbl-classify-compat.h
ldconfig.h
ldsodefs.h dlfcn: Rework static dlopen hooks 2021-06-03 09:12:05 +02:00
libBrokenLocale.abilist
libanl.abilist
libc-lock.h Remove pthread_key_create-related internals from libc-lock.h 2021-04-21 19:49:51 +02:00
libc-mmap.h
libc-mtag.h
libc-start.h
libc-symver.h
libc-tsd.h
libc.abilist Make sysdeps/generic/libc.abilist empty 2021-05-13 21:28:17 +00:00
libc_start_call_main.h csu: Move calling main out of __libc_start_main_impl 2021-04-21 19:49:50 +02:00
libcrypt.abilist
libdl.abilist
libm-alias-double.h
libm-alias-float.h
libm-alias-float128.h
libm-alias-ldouble.h
libm-test-ulps
libm-test-ulps-name
libm.abilist
libnsl.abilist
libnss_compat.abilist
libnss_db.abilist
libnss_dns.abilist
libnss_files.abilist
libnss_hesiod.abilist
libnss_nis.abilist
libnss_nisplus.abilist
libpthread.abilist
libresolv.abilist
librt.abilist
libutil.abilist
link_map.h
linkmap.h
local-setxid.h
localplt.data
machine-gmon.h
machine-lock.h
machine-sp.h
malloc-alignment.h
malloc-machine.h
malloc-sysdep.h
math-barriers.h
math-nan-payload-double.h
math-nan-payload-float.h
math-narrow-alias-float128.h
math-tests-arch.h
math-tests-exceptions.h
math-tests-rounding.h
math-tests-snan-cast.h
math-tests-snan-payload.h
math-tests-snan.h
math-tests-trap-force.h
math-tests-trap.h
math-tests.h
math-type-macros-double.h
math-type-macros-float.h
math-type-macros-float128.h
math-type-macros-ldouble.h
math-type-macros.h
math-use-builtins-ceil.h
math-use-builtins-copysign.h
math-use-builtins-floor.h
math-use-builtins-fma.h
math-use-builtins-nearbyint.h
math-use-builtins-rint.h
math-use-builtins-round.h
math-use-builtins-roundeven.h Use GCC builtins for roundeven functions if desired. 2021-06-27 07:56:57 -07:00
math-use-builtins-sqrt.h
math-use-builtins-trunc.h
math-use-builtins.h Use GCC builtins for roundeven functions if desired. 2021-06-27 07:56:57 -07:00
math_ldbl.h
math_ldbl_opt.h
math_private.h
math_private_calls.h
memcopy.h
memusage.h
mmap_info.h
nan-high-order-bit.h
not-cancel.h
not-errno.h
nscd-types.h
pagecopy.h
paths.h
profil-counter.h
pty-private.h
register-dump.h
rtld-lowlevel.h
rtld_static_init.h elf: Partially initialize ld.so after static dlopen (bug 20802) 2021-05-17 10:06:57 +02:00
safe-fatal.h
setjmpP.h
sigcontextinfo.h
siglist-compat.c
siglist-compat.h
siglist.h
sigset-cvt-mask.h
sigsetops.h
single-thread.h
spawn_int_def.h posix: Add posix_spawn_file_actions_addclosefrom_np 2021-07-08 14:08:15 -03:00
stackguard-macros.h
stackinfo.h
stap-probe-machine.h
startup.h
stdio-lock.h
string_private.h
struct_stat_time64.h
symbol-hacks.h
sysdep-cancel.h
sysdep.h
thread_state.h
time-clockid.h
time64-compat.h y2038: Add support for 64-bit time on legacy ABIs 2021-06-15 10:42:11 -03:00
tininess.h
tls-internal-struct.h
tls-internal.c
tls-internal.h
tls-macros.h
tls-setup.h
tls.h
tst-audit.h
tst-stack-align.h Properly check stack alignment [BZ #27901] 2021-05-24 07:42:12 -07:00
unsecvars.h
unwind-arch.h
unwind-dw2-fde-glibc.c
unwind-dw2-fde.c
unwind-dw2-fde.h
unwind-dw2.c
unwind-link.h
unwind-pe.c
unwind-pe.h
unwind-resume.c
unwind-resume.h
unwind.h
utmp-equal.h
xstatver.h