The gnulib module 'open' supports O_CLOEXEC since 2017-08-14. We can use it to make multithreaded application that call fork() and exec() more robust. Here are proposed patches. How about module 'fts'? Should the directory fds that it allocates also be made O_CLOEXEC? 2020-05-27 Bruno Haible relocatable-prog: Make more robust in multithreaded applications. * lib/progreloc.c (O_CLOEXEC): Define fallback to 0 when use from module relocatable-prog-wrapper. (find_executable): Pass an O_CLOEXEC flag to open(). * modules/relocatable-prog (Depends-on): Add 'open'. 2020-05-27 Bruno Haible getloadavg: Make more robust in multithreaded applications. * lib/getloadavg.c (getloadavg): Pass an O_CLOEXEC flag to open(). Simplify use of O_CLOEXEC. * modules/getloadavg (Depends-on): Add 'open'. 2020-05-27 Bruno Haible vma-iter: Make more robust in multithreaded applications. * lib/vma-iter.c (rof_open, vma_iterate): Pass an O_CLOEXEC flag to open(). * modules/vma-iter (Depends-on): Add 'open'. 2020-05-27 Bruno Haible truncate: Make more robust in multithreaded applications. * lib/truncate.c (truncate): Pass an O_CLOEXEC flag to open(). 2020-05-27 Bruno Haible pagealign_alloc: Make more robust in multithreaded applications. * lib/pagealign_alloc.c (pagealign_alloc): Pass an O_CLOEXEC flag to open(). * modules/pagealign_alloc (Depends-on): Add 'open'. 2020-05-27 Bruno Haible openat: Make more robust in multithreaded applications. * lib/openat.c (openat_needs_fchdir): Pass an O_CLOEXEC flag to open(). 2020-05-27 Bruno Haible at-internal: Make more robust in multithreaded applications. * lib/openat-proc.c (openat_proc_name): Pass an O_CLOEXEC flag to open(). 2020-05-27 Bruno Haible mountlist: Make more robust in multithreaded applications. * lib/mountlist.c (read_file_system_list): Pass an O_CLOEXEC flag to open(). * modules/mountlist (Depends-on): Add 'open'. 2020-05-27 Bruno Haible login_tty: Make more robust in multithreaded applications. * lib/login_tty.c (login_tty): Pass an O_CLOEXEC flag to open(). * modules/login_tty (Depends-on): Add 'open'. 2020-05-27 Bruno Haible javacomp: Make more robust in multithreaded applications. * lib/javacomp.c (get_classfile_version): Pass an O_CLOEXEC flag to open(). * modules/javacomp (Depends-on): Add 'open'. 2020-05-27 Bruno Haible getprogname: Make more robust in multithreaded applications. * lib/getprogname.c (getprogname): Pass an O_CLOEXEC flag to open(). * modules/getprogname (Depends-on): Add 'open'. 2020-05-27 Bruno Haible get_progname_of: Make more robust in multithreaded applications. * lib/get_progname_of.c (get_progname_of): Pass an O_CLOEXEC flag to open(). * modules/get_progname_of (Depends-on): Add 'open'. 2020-05-27 Bruno Haible get_ppid_of: Make more robust in multithreaded applications. * lib/get_ppid_of.c (get_ppid_of): Pass an O_CLOEXEC flag to open(). * modules/get_ppid_of (Depends-on): Add 'open'. 2020-05-27 Bruno Haible get-rusage-as: Make more robust in multithreaded applications. * lib/get-rusage-as.c (get_rusage_as_via_setrlimit): Pass an O_CLOEXEC flag to open(). * modules/get-rusage-as (Depends-on): Add 'open'. 2020-05-27 Bruno Haible crypto/gc: Make more robust in multithreaded applications. * lib/gc-gnulib.c (randomize): Pass an O_CLOEXEC flag to open(). * modules/crypto/gc (Depends-on): Add 'open'. 2020-05-27 Bruno Haible copy-file: Make more robust in multithreaded applications. * lib/copy-file.c (qcopy_file_preserving): Pass an O_CLOEXEC flag to open(). 2020-05-27 Bruno Haible chown: Make more robust in multithreaded applications. * lib/chown.c (rpl_chown): Pass an O_CLOEXEC flag to open(). 2020-05-27 Bruno Haible doc: Fix statement about O_CLOEXEC (wrong since 2017-08-14). * doc/posix-headers/fcntl.texi: Gnulib no longer defines O_CLOEXEC to 0.