This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Remove os.tmpnam() and os.tempnam()
Type: resource usage Stage:
Components: Documentation, Extension Modules Versions: Python 3.0
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, gvanrossum, loewis
Priority: normal Keywords: patch

Created on 2007-10-23 21:22 by christian.heimes, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
py3k_remove_os_tmpnam.patch christian.heimes, 2007-10-23 21:22
py3k_remove_os_tmp.patch christian.heimes, 2007-10-25 23:00
Messages (11)
msg56693 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-10-23 21:22
I couldn't stand the compiler warnings any more. :)

The patch removes os.tmpnam() and os.tempnam() from the posix module. It
also updates the docs and tests. TMP_MAX is kept for the tempfile
module. I haven't figured out how to remove the defines from pyconfig.h.
I guess they are always added by autoconf/automake.
msg56694 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-10-23 21:30
-1. First, they are linker warnings, not compiler warnings (I suppose),
plus they are meaningless in the context of Python.
msg56695 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-10-23 22:37
Martin, why do we need to keep these when we already have tempfile.py? 
I don't see that they solve any particular POSIX compatibility
requirement.  And they *are* unsafe.  (Admitted, sometimes there's no
alternative -- even tempfile.py still provides unsafe APIs by necessity.)
msg56697 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-10-23 23:55
First, you are right. It's not a compiler but a linker warning.

I don't see the point in keeping the methods. They are dangerous to use,
warned upon for a long time and they have a sane replacement that does a
far better job.
msg56700 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-10-24 05:56
Removing them because there is a replacement already is a better reason
than removing them because they give (bogus) warnings, so I'm -0 now.

As you say, tempfile is not any better from a security point of view in
the cases where tmpnam or tempnam would be used (e.g. if you want a
child process create a file whose name you specify).

Whether the tempfile.py implementation is actually better than the one
in the C library, I cannot tell (hence the -0: I don't know whether
tempfile.py or the C library wrapper should be removed). One issue I
just noticed is that tempfile.mkstemp promise of not inheriting the file
descriptor is bogus in the presence of threads and race conditions.

If the rationale for the patch is to eliminate duplication, then
os.tmpfile should be removed as well.
msg56738 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-10-25 09:44
os.tmpfile() is the only method that has no duplicate in tempfile. I
chose to keep it for this very reason. But you made good point, too.
What do you think about renaming tmpfile to _tmpfile and make it
available from the tempfile module as tempfile.tmpfile()?

I totally agree with your opinion on tmpnam and tempnam. As far as I
know it's impossible to prevent a child process from doing something
harmful. The child must be mature enough to do the right think and open
a file with the correct flags.

The promise of tempfile.mkstemp is also bogus for every OS except
Windows. IIRC only Windows supports O_NOINHERIT.

Let me rephrase the rational for my patch: I want to remove duplicate
code to have just but one implementation to create a temporary file
(name). I want the one implementation be under our control and not
depend on some possible broken or stupid C library like Windows where
tmpnam may create the temporary files in C:\. I want an unified way to
get the TEMP dir independent of the API.
msg56750 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-10-25 17:12
> os.tmpfile() is the only method that has no duplicate in tempfile.

Why do you say that? tempfile.mkstemp() does essentially the same
as os.tmpfile().

> The promise of tempfile.mkstemp is also bogus for every OS except
> Windows. IIRC only Windows supports O_NOINHERIT.

Please read the code. It tries to set the CLOEXEC flag on Unix,
which should work on most systems.

> Let me rephrase the rational for my patch: I want to remove duplicate
> code to have just but one implementation to create a temporary file
> (name). I want the one implementation be under our control and not
> depend on some possible broken or stupid C library like Windows where
> tmpnam may create the temporary files in C:\. I want an unified way to
> get the TEMP dir independent of the API.

As I said, I agree with most of this rationale, except that I'm
uncertain whether it is good to trade a stupid C library for a
stupid Python implementation.

With this rationale, again, I think tmpfile should be removed as
well.

Regards,
Martin
msg56756 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-10-25 22:42
Christian can you revise your patch to also remove os.tmpfile per
Martin's request?  Make sure unit tests and docs are fixed too.
msg56758 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-10-25 22:52
Guido van Rossum wrote:
> Christian can you revise your patch to also remove os.tmpfile per
> Martin's request?  Make sure unit tests and docs are fixed too.

I can do that for you. But I still believe that os.tmpfile() works
different than tempfile.mkstemp(). The former returns a file descriptor
of a file w/o directory entry and the later a file in tempfile.tempdir.

Christian
msg56760 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-10-25 23:00
2007/10/25, Christian Heimes <report@bugs.python.org>:
> I can do that for you. But I still believe that os.tmpfile() works
> different than tempfile.mkstemp(). The former returns a file descriptor
> of a file w/o directory entry and the later a file in tempfile.tempdir.

True. But tempfile.TemporaryFile() returns a temp file without a name.
msg56762 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-10-25 23:19
Committed revision 58657.

Thanks!
History
Date User Action Args
2022-04-11 14:56:27adminsetgithub: 45659
2007-10-25 23:19:02gvanrossumsetstatus: open -> closed
resolution: accepted
messages: + msg56762
2007-10-25 23:00:51christian.heimessetfiles: + py3k_remove_os_tmp.patch
2007-10-25 23:00:33gvanrossumsetmessages: + msg56760
2007-10-25 22:52:06christian.heimessetmessages: + msg56758
2007-10-25 22:43:00gvanrossumsetmessages: + msg56756
2007-10-25 17:12:03loewissetmessages: + msg56750
title: Remove os.tmpnam() and os.tempnam() [patch] -> Remove os.tmpnam() and os.tempnam()
2007-10-25 09:44:29christian.heimessetmessages: + msg56738
2007-10-24 05:56:19loewissetmessages: + msg56700
2007-10-23 23:55:46christian.heimessetmessages: + msg56697
2007-10-23 22:37:41gvanrossumsetnosy: + gvanrossum
messages: + msg56695
2007-10-23 21:30:01loewissetkeywords: + patch
nosy: + loewis
messages: + msg56694
2007-10-23 21:22:21christian.heimescreate