mkstemp vs. text mode

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

mkstemp vs. text mode

Eric Blake (cygwin)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Should we change mkstemp to always open in binary mode, regardless of the
mount mode of the directory of the template name?  Arguments for this is
that mkstemp is often used by programs for binary data, where a text-mode
/tmp mount point would corrupt that data if we defer to the mount point.
Also, a temp file is an intermediate data storage location, similar to
pipes, and we currently treat pipes as binary by default; a program
copying data to a temp file, then from there to a final destination, only
needs text mode on the final destination.  Programs that really want a
text-mode temp file can do setmode after the fact, but this is probably
less common.

This should still be a trivial patch.  Meanwhile, I will start the process
of getting an employee disclaimer for Red Hat (it took me almost a year to
get one signed for FSF).

2006-04-17  Eric Blake  <[hidden email]>

        * mktemp.cc (_gettemp): Open temp files in binary mode.

- --
Life is short - so eat dessert first!

Eric Blake             [hidden email]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEQ4ee84KuGfSFAYARAkpIAKCYK1IRVHZ4dMkWUTgyzycxyMkBawCfXgz4
wCvt41FDUXLB67JFnv+vZgg=
=LLV/
-----END PGP SIGNATURE-----

Index: mktemp.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/mktemp.cc,v
retrieving revision 1.2
diff -u -p -r1.2 mktemp.cc
--- mktemp.cc 25 May 2005 03:43:58 -0000 1.2
+++ mktemp.cc 17 Apr 2006 12:15:39 -0000
@@ -105,7 +105,8 @@ _gettemp(char *path, int *doopen, int do
     {
       if (doopen)
  {
-  if ((*doopen = open (path, O_CREAT | O_EXCL | O_RDWR, 0600)) >= 0)
+  if ((*doopen = open (path, O_CREAT | O_EXCL | O_RDWR | O_BINARY,
+       S_IRUSR | S_IWUSR)) >= 0)
     return 1;
   if (errno != EEXIST)
     return 0;
Reply | Threaded
Open this post in threaded view
|

Re: mkstemp vs. text mode

Christopher Faylor-2
On Mon, Apr 17, 2006 at 06:18:38AM -0600, Eric Blake wrote:

>Should we change mkstemp to always open in binary mode, regardless of
>the mount mode of the directory of the template name?  Arguments for
>this is that mkstemp is often used by programs for binary data, where a
>text-mode /tmp mount point would corrupt that data if we defer to the
>mount point.  Also, a temp file is an intermediate data storage
>location, similar to pipes, and we currently treat pipes as binary by
>default; a program copying data to a temp file, then from there to a
>final destination, only needs text mode on the final destination.
>Programs that really want a text-mode temp file can do setmode after
>the fact, but this is probably less common.
>
>This should still be a trivial patch.  Meanwhile, I will start the
>process of getting an employee disclaimer for Red Hat (it took me
>almost a year to get one signed for FSF).
>
>2006-04-17 Eric Blake <[hidden email]>
>
> * mktemp.cc (_gettemp): Open temp files in binary mode.

Yes, I think it makes sense to open temp files in binary but I'll bet
that someone is relying on textmode behavior.  Nevertheless, I've
applied the patch.

Let the cygwin ML whines begin...

cgf
Reply | Threaded
Open this post in threaded view
|

RE: mkstemp vs. text mode

Gary R. Van Sickle
> From: Christopher Faylor
[snip]
> Yes, I think it makes sense to open temp files in binary but
> I'll bet that someone is relying on textmode behavior.  

I'll see that bet and raise you; I'll bet this results in massive problems.

> Nevertheless, I've applied the patch.
>
> Let the cygwin ML whines begin...
>
> cgf

Ok, I'm about to give it a try (assuming this is in the latest snapshot).
When I have some positive results, I shall post them to cygwin@.  If I have
negative results, should I post them there as well, or would that be
considered a "whine"?

--
Gary R. Van Sickle
 

Reply | Threaded
Open this post in threaded view
|

RE: mkstemp vs. text mode

Gary R. Van Sickle
> From: Gary R. Van Sickle
>
> > From: Christopher Faylor
> [snip]
> > Yes, I think it makes sense to open temp files in binary
> but I'll bet
> > that someone is relying on textmode behavior.
>
> I'll see that bet and raise you; I'll bet this results in
> massive problems.
>
> > Nevertheless, I've applied the patch.
> >
> > Let the cygwin ML whines begin...
> >
> > cgf
>
> Ok, I'm about to give it a try (assuming this is in the
> latest snapshot).
> When I have some positive results, I shall post them to
> cygwin@.  If I have negative results, should I post them
> there as well, or would that be considered a "whine"?
>
> --
> Gary R. Van Sickle

Last snapshot 4/13, never mind: any potential whine reports will have to
wait for another day.

--
Gary R. Van Sickle
 

Reply | Threaded
Open this post in threaded view
|

[NON-WHINE] RE: mkstemp vs. text mode

Gary R. Van Sickle
> From: Gary R. Van Sickle
>
> > From: Gary R. Van Sickle
> >
> > > From: Christopher Faylor
> > [snip]
> > > Yes, I think it makes sense to open temp files in binary
> > but I'll bet
> > > that someone is relying on textmode behavior.
> >
> > I'll see that bet and raise you; I'll bet this results in massive
> > problems.
> >

Welp, looks like I (probably) lose that hand (happily).  Using:

CYGWIN_NT-5.1 DFW5RB41 1.5.20s(0.155/4/2) 20060418 12:31:05 i686 Cygwin

with a /tmp mounted as text mode works fine for a configure, build, and
install of wxWindows.  The configure does most of the temp file
machinations, with about 2000 add, modify, and remove events in the /tmp
directory, as reported by a program I have for monitoring such things.

--
Gary R. Van Sickle

Reply | Threaded
Open this post in threaded view
|

RE: [NON-WHINE] RE: mkstemp vs. text mode

Gary R. Van Sickle
More non-negative news: The Cygwin/X Server creates its own subdirectory and
a bunch of files in /tmp and still appears to work fine.

--
Gary R. Van Sickle
 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Gary R.
> Van Sickle
> Sent: Wednesday, April 19, 2006 8:56 PM
> To: [hidden email]
> Cc: [hidden email]
> Subject: [NON-WHINE] RE: mkstemp vs. text mode
>
> > From: Gary R. Van Sickle
> >
> > > From: Gary R. Van Sickle
> > >
> > > > From: Christopher Faylor
> > > [snip]
> > > > Yes, I think it makes sense to open temp files in binary
> > > but I'll bet
> > > > that someone is relying on textmode behavior.
> > >
> > > I'll see that bet and raise you; I'll bet this results in massive
> > > problems.
> > >
>
> Welp, looks like I (probably) lose that hand (happily).  Using:
>
> CYGWIN_NT-5.1 DFW5RB41 1.5.20s(0.155/4/2) 20060418 12:31:05
> i686 Cygwin
>
> with a /tmp mounted as text mode works fine for a configure,
> build, and install of wxWindows.  The configure does most of
> the temp file machinations, with about 2000 add, modify, and
> remove events in the /tmp directory, as reported by a program
> I have for monitoring such things.
>
> --
> Gary R. Van Sickle
>