glibc/sysdeps/unix
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
..
alpha Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
arm Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
bsd login: Hidden prototypes for _getpt, __ptsname_r, grantpt, unlockpt 2021-06-30 07:28:12 +02:00
i386 Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
inet Remove obsolete, never-implemented XSI STREAMS declarations 2019-03-14 15:44:15 +01:00
mips Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
powerpc Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
sh Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
sysv/linux posix: Add posix_spawn_file_actions_addclosefrom_np 2021-07-08 14:08:15 -03:00
x86_64 Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
confstr.h
get_child_max.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
getlogin_r.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
getlogin.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
getpagesize.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
grantpt.c login: Hidden prototypes for _getpt, __ptsname_r, grantpt, unlockpt 2021-06-30 07:28:12 +02:00
ifreq.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
Implies
make-syscalls.sh Add SYSCALL_ULONG_ARG_[12] to pass long to syscall [BZ #25810] 2020-04-29 05:35:34 -07:00
Makefile Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
s-proto-cancel.S
s-proto.S
setxid.h
sockatmark.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
syscall-template.S Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
syscall.S Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
syscalls.list signal: Add __libc_sigaction 2021-03-18 15:54:39 -03:00
sysdep.h Linux: Explicitly disable cancellation checking in the dynamic loader 2021-05-10 10:31:41 +02:00