Subject: bug#15015: Fix some minor races in hosts lacking mkostemp

From: Eli Zaretskii <[email-masked]>
Date: Sat, 03 Aug 2013 17:55:19 +0300

> Date: Sat, 03 Aug 2013 07:40:35 -0700
> From: Paul Eggert <[email-masked]>
> CC: [email-masked]
> 
> On 08/03/2013 01:38 AM, Eli Zaretskii wrote:
> 
> > the gnulib mkostemp module ... relies on quite a few functions that are
> > redefined in Emacs, and I have no idea what will this do to the gnulib
> > implementation.
> 
> I don't see the problem; could you please explain further?
> On Microsoft platforms, the only functions that the mkostemp
> module should use should be getenv, strlen, memcmp,
> gettimeofday, open (..., O_RDWR | O_CREAT | O_EXCL, S_IRUSR
> | S_IWUSR), and lstat, and this sort of thing is already
> working elsewhere.

gettimeofday, open, and lstat are implemented by Emacs in w32.c.  At
lest the last 2 are not equivalent to what gnulib uses.

> > Also, since we still didn't remove the support for
> > MS-Windows builds that use nt/configure.bat and the makefile-w32.in
> > files, the uses of mktemp in the Emacs sources should be left alone
> > for now, if we go this route.
> 
> Presumably nt/configure.bat and makefile-w32.in could be updated
> to compile the new files.  This sort of thing should be routine,
> if that avenue is still supported.

This "support" needs volunteers, which didn't yet show up.  But if
there are two alternatives to fix a problem, and one of them breaks
this "support" while the other doesn't, I'd prefer the latter.

> > I thought of a far easier solution: use the same code as sys_mktemp
> > does, but use 'open' or '_sopen' instead of faccessat.
> 
> This won't suffice for POSIXish platforms that lack mkostemp
> but have 'open' with O_EXCL.  Solaris is one example.  The
> Gnulib mkostemp module fixes the races on those platforms.

That's OK.  We can always install the gnulib stuff for those other
platforms, and work around it on Windows.