Go to file
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
argp
assert
benchtests
bits Update floating-point feature test macro handling for C2X 2021-06-01 14:22:06 +00:00
catgets
ChangeLog.old
conform
crypt
csu
ctype Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
debug Remove all usage of @BASH@ or ${BASH} in installed files, and hardcode /bin/bash instead 2021-05-12 07:47:11 +05:30
dirent
dlfcn elf: Clean up GLIBC_PRIVATE exports of internal libdl symbols 2021-07-07 08:41:24 +02:00
elf elf/tests: Make thrlock and noload depend on libm 2021-07-08 13:39:19 +05:30
gmon
gnulib
grp
gshadow
hesiod
htl
hurd
iconv libio: Replace internal _IO_getdelim symbol with __getdelim 2021-07-07 18:33:52 +02:00
iconvdata
include posix: Add posix_spawn_file_actions_addclosefrom_np 2021-07-08 14:08:15 -03:00
inet inet: Add hidden prototype for __inet_network 2021-07-07 18:33:52 +02:00
intl
io io: Add closefrom [BZ #10353] 2021-07-08 14:08:14 -03:00
libio libio: Replace internal _IO_getdelim symbol with __getdelim 2021-07-07 18:33:52 +02:00
locale
localedata
login login: Move libutil into libc 2021-06-30 08:43:37 +02:00
mach
malloc _int_realloc is static 2021-07-08 18:47:21 +05:30
manual io: Add closefrom [BZ #10353] 2021-07-08 14:08:14 -03:00
math
mathvec
misc
nis
nptl nptl: Reduce the GLIBC_PRIVATE ABI 2021-07-07 08:41:21 +02:00
nptl_db nptl_db: Re-use the ELF-to-abilist converter for ABI checking 2021-06-29 22:17:08 +02:00
nscd
nss nss: Do not install static linker input files for libnss_files 2021-07-08 14:06:53 +02:00
po
posix posix: Add posix_spawn_file_actions_addclosefrom_np 2021-07-08 14:08:15 -03:00
pwd
resolv resolv: Move libanl into libc (if libpthread is in libc) 2021-07-02 11:45:00 +02:00
resource
rt
scripts Use Linux 5.13 in build-many-glibcs.py 2021-06-30 13:29:08 +00:00
setjmp
shadow
signal
socket
soft-fp soft-fp: Add __extendhfsf2/__extendhfdf2, __truncsfhf2/__truncdfhf2, __eqhf2/__nehf2 2021-07-07 08:01:32 -07:00
stdio-common libio: Replace internal _IO_getdelim symbol with __getdelim 2021-07-07 18:33:52 +02:00
stdlib Move mcheck symbol from stdlib to malloc 2021-07-08 18:47:21 +05:30
string
sunrpc
support support: Add support_stack_alloc 2021-07-08 13:48:06 -03:00
sysdeps posix: Add posix_spawn_file_actions_addclosefrom_np 2021-07-08 14:08:15 -03:00
sysvipc
termios
time
timezone
wcsmbs
wctype
.gitattributes
.gitignore
abi-tags
aclocal.m4
config.h.in
config.make.in
configure
configure.ac
COPYING
COPYING.LIB
extra-lib.mk
gen-locales.mk
INSTALL
libc-abis
libof-iterator.mk
LICENSES
MAINTAINERS
Makeconfig resolv: Move libanl into libc (if libpthread is in libc) 2021-07-02 11:45:00 +02:00
Makefile
Makefile.help
Makefile.in
Makerules
NEWS posix: Add posix_spawn_file_actions_addclosefrom_np 2021-07-08 14:08:15 -03:00
o-iterator.mk
README
Rules Add mcheck tests to malloc 2021-07-02 17:03:42 +05:30
shlib-versions
test-skeleton.c
version.h

This directory contains the sources of the GNU C Library.
See the file "version.h" for what release version you have.

The GNU C Library is the standard system C library for all GNU systems,
and is an important part of what makes up a GNU system.  It provides the
system API for all programs written in C and C-compatible languages such
as C++ and Objective C; the runtime facilities of other programming
languages use the C library to access the underlying operating system.

In GNU/Linux systems, the C library works with the Linux kernel to
implement the operating system behavior seen by user applications.
In GNU/Hurd systems, it works with a microkernel and Hurd servers.

The GNU C Library implements much of the POSIX.1 functionality in the
GNU/Hurd system, using configurations i[4567]86-*-gnu.

When working with Linux kernels, this version of the GNU C Library
requires Linux kernel version 3.2 or later.

Also note that the shared version of the libgcc_s library must be
installed for the pthread library to work correctly.

The GNU C Library supports these configurations for using Linux kernels:

	aarch64*-*-linux-gnu
	alpha*-*-linux-gnu
	arc*-*-linux-gnu
	arm-*-linux-gnueabi
	csky-*-linux-gnuabiv2
	hppa-*-linux-gnu
	i[4567]86-*-linux-gnu
	x86_64-*-linux-gnu	Can build either x86_64 or x32
	ia64-*-linux-gnu
	m68k-*-linux-gnu
	microblaze*-*-linux-gnu
	mips-*-linux-gnu
	mips64-*-linux-gnu
	powerpc-*-linux-gnu	Hardware or software floating point, BE only.
	powerpc64*-*-linux-gnu	Big-endian and little-endian.
	s390-*-linux-gnu
	s390x-*-linux-gnu
	riscv32-*-linux-gnu
	riscv64-*-linux-gnu
	sh[34]-*-linux-gnu
	sparc*-*-linux-gnu
	sparc64*-*-linux-gnu

If you are interested in doing a port, please contact the glibc
maintainers; see https://www.gnu.org/software/libc/ for more
information.

See the file INSTALL to find out how to configure, build, and install
the GNU C Library.  You might also consider reading the WWW pages for
the C library at https://www.gnu.org/software/libc/.

The GNU C Library is (almost) completely documented by the Texinfo manual
found in the `manual/' subdirectory.  The manual is still being updated
and contains some known errors and omissions; we regret that we do not
have the resources to work on the manual as much as we would like.  For
corrections to the manual, please file a bug in the `manual' component,
following the bug-reporting instructions below.  Please be sure to check
the manual in the current development sources to see if your problem has
already been corrected.

Please see https://www.gnu.org/software/libc/bugs.html for bug reporting
information.  We are now using the Bugzilla system to track all bug reports.
This web page gives detailed information on how to report bugs properly.

The GNU C Library is free software.  See the file COPYING.LIB for copying
conditions, and LICENSES for notices about a few contributions that require
these additional notices to be distributed.  License copyright years may be
listed using range notation, e.g., 1996-2015, indicating that every year in
the range, inclusive, is a copyrightable year that would otherwise be listed
individually.