public inbox for cygwin-developers@cygwin.com
 help / color / mirror / Atom feed
* Extending domain of O_TMPFILE?
@ 2021-02-05 10:31 Mark Geisert
  2021-02-05 11:26 ` Corinna Vinschen
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Geisert @ 2021-02-05 10:31 UTC (permalink / raw)
  To: cygwin-developers

Hi folks,
I've been following up on a response I made to a Cygwin user in
https://cygwin.com/pipermail/cygwin/2021-January/247306.html .
I've figured out that Cygwin's implementation of the open() flag O_TMPFILE 
follows Linux in that one can't specify the name of a file when using this 
flag.  User supplies only the path, and Cygwin chooses an obscure file 
name for you.

That means the OP's suggested improvement of applying O_TMPFILE semantics 
to files created by tmpfile() won't work.

Could we consider expanding the domain of O_TMPFILE so that the user can 
supply a name for the temporary file rather than just the path to its 
directory?  I've been playing around with proof-of-concept code but I want 
to make sure this is acceptable before submitting implementation patches.

This would be a Cygwin-specific enhancement to a Linux-specific feature. 
I haven't checked yet if the BSDs have O_TMPFILE in any form.
Thanks for any feedback!

..mark

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Extending domain of O_TMPFILE?
  2021-02-05 10:31 Extending domain of O_TMPFILE? Mark Geisert
@ 2021-02-05 11:26 ` Corinna Vinschen
  2021-02-06  7:56   ` Mark Geisert
  0 siblings, 1 reply; 5+ messages in thread
From: Corinna Vinschen @ 2021-02-05 11:26 UTC (permalink / raw)
  To: cygwin-developers

On Feb  5 02:31, Mark Geisert wrote:
> Hi folks,
> I've been following up on a response I made to a Cygwin user in
> https://cygwin.com/pipermail/cygwin/2021-January/247306.html .
> I've figured out that Cygwin's implementation of the open() flag O_TMPFILE
> follows Linux in that one can't specify the name of a file when using this
> flag.  User supplies only the path, and Cygwin chooses an obscure file name
> for you.
> 
> That means the OP's suggested improvement of applying O_TMPFILE semantics to
> files created by tmpfile() won't work.

I don't understand the problem.  tmpfile(3) does not take filenames, it
creates its own filenames.  Thus, just adding O_TMPFILE in _tmpfile_r's
and _tmpfile64's calls to open() on systems supporting this flag and not
calling _remove_r subsequently would already do the trick.


Corinna

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Extending domain of O_TMPFILE?
  2021-02-05 11:26 ` Corinna Vinschen
@ 2021-02-06  7:56   ` Mark Geisert
  2021-02-08 10:34     ` Corinna Vinschen
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Geisert @ 2021-02-06  7:56 UTC (permalink / raw)
  To: Corinna Vinschen via Cygwin-developers

On Fri, 5 Feb 2021, Corinna Vinschen via Cygwin-developers wrote:
> On Feb  5 02:31, Mark Geisert wrote:
>> Hi folks,
>> I've been following up on a response I made to a Cygwin user in
>> https://cygwin.com/pipermail/cygwin/2021-January/247306.html .
>> I've figured out that Cygwin's implementation of the open() flag O_TMPFILE
>> follows Linux in that one can't specify the name of a file when using this
>> flag.  User supplies only the path, and Cygwin chooses an obscure file name
>> for you.
>>
>> That means the OP's suggested improvement of applying O_TMPFILE semantics to
>> files created by tmpfile() won't work.
>
> I don't understand the problem.  tmpfile(3) does not take filenames, it
> creates its own filenames.  Thus, just adding O_TMPFILE in _tmpfile_r's
> and _tmpfile64's calls to open() on systems supporting this flag and not
> calling _remove_r subsequently would already do the trick.

That's what I thought too.  But the open() fails and strace reveals ENOENT 
is being generated at syscalls.cc:1516.  The unix_path arg to open() needs 
to indicate a directory, but _tmpfile_r is currently passing in a filename
path generated by _tmpnam_r.

So that's what led me to contemplate extending the domain of O_TMPFILE 
such that one could proactively name the temporary file.  But it's 
probably more sane to just have _tmpfile_r skip the generation of a file 
name and instead pass in a directory name to open(), either from 
environment variable TMPDIR or the libc #define P_tmpdir.
Does this sound OK?
Thanks,

..mark

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Extending domain of O_TMPFILE?
  2021-02-06  7:56   ` Mark Geisert
@ 2021-02-08 10:34     ` Corinna Vinschen
  2021-02-09 10:15       ` Mark Geisert
  0 siblings, 1 reply; 5+ messages in thread
From: Corinna Vinschen @ 2021-02-08 10:34 UTC (permalink / raw)
  To: cygwin-developers

On Feb  5 23:56, Mark Geisert wrote:
> On Fri, 5 Feb 2021, Corinna Vinschen via Cygwin-developers wrote:
> > On Feb  5 02:31, Mark Geisert wrote:
> > > Hi folks,
> > > I've been following up on a response I made to a Cygwin user in
> > > https://cygwin.com/pipermail/cygwin/2021-January/247306.html .
> > > I've figured out that Cygwin's implementation of the open() flag O_TMPFILE
> > > follows Linux in that one can't specify the name of a file when using this
> > > flag.  User supplies only the path, and Cygwin chooses an obscure file name
> > > for you.
> > > 
> > > That means the OP's suggested improvement of applying O_TMPFILE semantics to
> > > files created by tmpfile() won't work.
> > 
> > I don't understand the problem.  tmpfile(3) does not take filenames, it
> > creates its own filenames.  Thus, just adding O_TMPFILE in _tmpfile_r's
> > and _tmpfile64's calls to open() on systems supporting this flag and not
> > calling _remove_r subsequently would already do the trick.
> 
> That's what I thought too.  But the open() fails and strace reveals ENOENT
> is being generated at syscalls.cc:1516.  The unix_path arg to open() needs
> to indicate a directory, but _tmpfile_r is currently passing in a filename
> path generated by _tmpnam_r.
> 
> So that's what led me to contemplate extending the domain of O_TMPFILE such
> that one could proactively name the temporary file.  But it's probably more
> sane to just have _tmpfile_r skip the generation of a file name and instead
> pass in a directory name to open(), either from environment variable TMPDIR
> or the libc #define P_tmpdir.
> Does this sound OK?

Yes, the matching patch should be in _tmpfile_r / _tmpfile64_r.

Alternatively, and probably much simpler, you could define our
own tmpfile / tmpfile64 in Cygwin's syscalls.cc, kind of like this:

  extern "C" FILE *
  tmpfile (void)
  {
    [...]
  }

  EXPORT_ALIAS (tmpfile, tmpfile64)


Thanks,
Corinna

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Extending domain of O_TMPFILE?
  2021-02-08 10:34     ` Corinna Vinschen
@ 2021-02-09 10:15       ` Mark Geisert
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Geisert @ 2021-02-09 10:15 UTC (permalink / raw)
  To: cygwin-developers

Corinna Vinschen via Cygwin-developers wrote:
> On Feb  5 23:56, Mark Geisert wrote:
[...]
>> So that's what led me to contemplate extending the domain of O_TMPFILE such
>> that one could proactively name the temporary file.  But it's probably more
>> sane to just have _tmpfile_r skip the generation of a file name and instead
>> pass in a directory name to open(), either from environment variable TMPDIR
>> or the libc #define P_tmpdir.
>> Does this sound OK?
> 
> Yes, the matching patch should be in _tmpfile_r / _tmpfile64_r.
> 
> Alternatively, and probably much simpler, you could define our
> own tmpfile / tmpfile64 in Cygwin's syscalls.cc, kind of like this:
> 
>    extern "C" FILE *
>    tmpfile (void)
>    {
>      [...]
>    }
> 
>    EXPORT_ALIAS (tmpfile, tmpfile64)

Oh, that makes much more sense as the code site.  I've a little more testing to 
do, then will submit the patch.
Thanks!

..mark

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-02-09 10:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-05 10:31 Extending domain of O_TMPFILE? Mark Geisert
2021-02-05 11:26 ` Corinna Vinschen
2021-02-06  7:56   ` Mark Geisert
2021-02-08 10:34     ` Corinna Vinschen
2021-02-09 10:15       ` Mark Geisert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).