kernel: Implement O_CLOEXEC
authorFrançois Tigeot <ftigeot@wolfpond.org>
Mon, 30 Jul 2012 20:39:46 +0000 (22:39 +0200)
committerFrançois Tigeot <ftigeot@wolfpond.org>
Tue, 31 Jul 2012 06:27:13 +0000 (08:27 +0200)
commit6e4ea98e8a4f403762582bd657180d3bd3636505
treeddb6ed8bd12be1277dc3bbe50469ddda18bbb483
parent1dc13257a62ef79987eea8072020520b1d6499d3
kernel: Implement O_CLOEXEC

* Using fcntl(2) just after open(2) is not enough to avoid race conditions
  in programs doing fork+exec sequences. Child processes may be created
  before fcntl() is run and inherit the parent's file descriptors.

* In some circonstances this behavior may even create security issues.

* O_CLOEXEC can be used to atomically set the close-on-exec flag for new
  file descriptors, avoiding the whole mess in the first place.

* Fixes issue #2356

Inspired-from: NetBSD
lib/libc/sys/open.2
sys/kern/vfs_syscalls.c
sys/sys/fcntl.h