glibc/sysdeps/unix
Adhemerval Zanella 805334b26c posix: Clear close-on-exec for posix_spawn adddup2 (BZ#23640)
Austin Group issue #411 [1] proposes that posix_spawn file action
posix_spawn_file_actions_adddup2 resets the close-on-exec when
source and destination refer to same file descriptor.

It solves the issue on multi-thread applications which uses
close-on-exec as default, and want to hand-chose specifically
file descriptor to purposefully inherited into a child process.
Current approach to achieve this scenario is to use two adddup2 file
actions and a temporary file description which do not conflict with
any other, coupled with a close file action to avoid leaking the
temporary file descriptor.  This approach, besides being complex,
may fail with EMFILE/ENFILE file descriptor exaustion.

This can be more easily accomplished with an in-place removal of
FD_CLOEXEC.  Although the resulting adddup2 semantic is slight
different than dup2 (equal file descriptors should be handled as
no-op), the proposed possible solution are either more complex
(fcntl action which a limited set of operations) or results in
unrequired operations (dup3 which also returns EINVAL for same
file descriptor).

Checked on aarch64-linux-gnu.

	[BZ #23640]
	* posix/tst-spawn.c (do_prepare, handle_restart, do_test): Add
	posix_spawn_file_actions_adddup2 test to check O_CLOCEXEC reset.
	* sysdeps/unix/sysv/linux/spawni.c (__spawni_child): Add
	close-on-exec reset for adddup2 file action.
	* sysdeps/posix/spawni.c (__spawni_child): Likewise.

[1] http://austingroupbugs.net/view.php?id=411
2019-01-03 14:38:01 -02:00
..
alpha Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
arm Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
bsd Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
i386 Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
inet Switch IDNA implementation to libidn2 [BZ #19728] [BZ #19729] [BZ #22247] 2018-05-23 15:27:24 +02:00
mips Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
powerpc Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
sh Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
sysv/linux posix: Clear close-on-exec for posix_spawn adddup2 (BZ#23640) 2019-01-03 14:38:01 -02:00
x86_64 Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
clock_gettime.c Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
clock_nanosleep.c Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
clock_settime.c Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
confstr.h
get_child_max.c Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
getlogin_r.c Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
getlogin.c Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
getpagesize.c Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
grantpt.c Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
ifreq.c Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
Implies
make-syscalls.sh Make llseek a compat symbol (bug 18471). 2018-05-22 15:44:01 +00:00
Makefile Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
pt-fcntl.c Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
s-proto-cancel.S
s-proto.S
setxid.h
sockatmark.c Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
stime.c Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
syscall-template.S Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
syscall.S Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
syscalls.list posix: Consolidate Linux fsync syscall 2017-05-18 18:06:47 -03:00
sysdep.h Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00