On 2/28/19 7:38 AM, co...@sdf.org wrote: > Hi folks, > > in Solaris 10 apparently O_CLOEXEC is not defined. > (got a bug report in http://gnats.netbsd.org/54025) > > Attached is a patch wrapping the code using it in #ifdef O_CLOEXEC.
Incomplete - if you are unable to atomically set the CLOEXEC flag during open() due to lack of O_CLOEXEC, then you should use fcntl(F_GETFD)/fcntl(F_SETFD) to set FD_CLOEXEC relatively soon after the open(), so that the fd is still properly closed on forks either way. In multi-threaded applications, O_CLOEXEC is essential to avoid data races where one thread calls fork() in between another window calling open() vs. fcntl() and thus inadvertently leaking the fd into the child; but since bash is single-threaded, the race is only possible via signal handlers, and hopefully bash isn't trying to fork from a signal handler that might be interrupting the window between open() and fcntl(). -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org