Subject: Re: bug#14803: Setting close-on-exec flag consistently

From: Eli Zaretskii <[email-masked]>
Date: Sun, 07 Jul 2013 05:46:27 +0300

> Date: Sat, 06 Jul 2013 14:43:26 -0700
> From: Paul Eggert <[email-masked]>
> CC: [email-masked]
> 
> > I assume that lib/fcntl.c and
> > lib/pipe2.c will not be compiled for w32, due to some configure test?
> 
> Yes, though that needs to be arranged.  The following further
> patch should do it:
> 
> === modified file 'ChangeLog'
> --- ChangeLog	2013-07-06 09:44:23 +0000
> +++ ChangeLog	2013-07-06 21:39:31 +0000
> @@ -1,7 +1,9 @@
>  2013-07-06  Paul Eggert  <[email-masked]>
>  
>  	Make file descriptors close-on-exec when possible (Bug#14803).
> -	* configure.ac (mkostemp): New function to check for.
> +	* configure.ac (ac_cv_func_fcntl, gl_cv_func_fcntl_f_dupfd_cloexec)
> +	(gl_cv_func_fcntl_f_dupfd_works, ac_cv_func_pipe2): Hotwire for MinGW.
> +	(mkostemp): New function to check for.
>  	(PTY_OPEN): Pass O_CLOEXEC to posix_openpt.
>  	* lib/fcntl.c, lib/getdtablesize.c, lib/pipe2.c, m4/fcntl.m4:
>  	* m4/getdtablesize.m4, m4/pipe2.m4: New files, taken from gnulib.
> 
> === modified file 'configure.ac'
> --- configure.ac	2013-07-06 07:04:07 +0000
> +++ configure.ac	2013-07-06 21:33:56 +0000
> @@ -634,6 +634,19 @@
>  # Avoid gnulib's threadlib module, as we do threads our own way.
>  AC_DEFUN([gl_THREADLIB])
>  
> +# On MinGW, Emacs supplies its own substitutes for some missing functions,
> +# so hotwire the cache to pretend to Gnulib that the functions work;
> +# that way, 'configure' won't arrange to build the Gnulib substitutes.
> +if test "$opsys" = mingw32; then
> +  # fcntl
> +  ac_cv_func_fcntl=emulated # Any single word other than 'no' will do.
> +  gl_cv_func_fcntl_f_dupfd_cloexec=yes # Actually 'no', but only 'yes' works.
> +  gl_cv_func_fcntl_f_dupfd_works='no, but Emacs emulates yes'
> +
> +  # pipe2
> +  ac_cv_func_pipe2='no, but Emacs emulates yes'
> +fi
> +

This should probably go into nt/mingw-cfg.site.

Thanks.