httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <>
Subject tempnam will ignore req->temp_dir if TMPDIR is set
Date Mon, 22 Apr 2002 08:52:52 GMT
tempnam(3) on linux says:

        Attempts to find an appropriate directory go  through  the
        following  steps:  (i)  In  case  the environment variable
        TMPDIR exists and contains  the  name  of  an  appropriate
        directory, that is used.  (ii) Otherwise, if the dir argu­
        ment is non-NULL and appropriate, it is used.  (iii)  Oth­
        erwise,  P_tmpdir  (as  defined in <stdio.h>) is used when
        appropriate.   (iv)  Finally   an   implementation-defined
        directory may be used.

which means that if TMPDIR env var is set, the req->temp_dir will be 
ignored, which may lead to confusion when someone expects to catch temp 
files in the directory they have explicitly specified. Should this be 

I'm talking about the code:

     while (--tries > 0) {
	if ( (name = tempnam(req->temp_dir, prefix)) == NULL )

in c/apache_request.c:ApacheRequest_tmpfile

Why do we need this while() loop? Does this very manpage on other 
systems suggest to do so?

Also according to the same manpage:

        The  tempnam()  function generates a different string each
        time it is called, up to TMP_MAX  (defined  in  <stdio.h>)
        times.  If  it  is  called  more  than  TMP_MAX times, the
        behaviour is implementation defined.

on my linux #define TMP_MAX 238328. Does it mean that after a quarter of 
million requests this function may fail? The manpage doesn't say if it 
talks about a single process or the whole system.

Finally it says:

        The precise meaning of `appropriate' is undefined;  it  is
        unspecified  how  accessibility  of  a directory is deter­
        mined.  Never use this function. Use mkstemp(3) instead.

Any comments about this bug comment?

I'm trying to push for adding a portable apr_tmp_dir() function, but I 
don't know if it's going to be added. There doesn't seem to be any 
interest in even discussing it :(

Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker     mod_perl Guide --->

View raw message