httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Hay <steve....@uk.radan.com>
Subject [PATCH libapreq-1.2] Re: [PATCH mp1.28] Clean up file uploaded by test suite
Date Thu, 21 Aug 2003 09:29:08 GMT
Stas Bekman wrote:

> Steve Hay wrote:
>
>> Stas Bekman wrote:
>>
>>> Do we have the same problem with Apache::Request?
>>
>>
>>
>> I don't think so, but I'm not sure where the uploaded data gets 
>> spooled to by Apache::Request.  (CGI.pm created "CGItemp<number>" 
>> files in my C:\Temp directory.  Where does Apache::Request put this 
>> data?)
>
>
> You can specify the temp dir in new(), with TEMP_DIR. it uses the 
> apreq prefix for temp files. see ApacheRequest_tmpfile() in 
> standard/c/apache_request.c. 

Thanks.  We definitely don't have a problem in that regard then: 
ApacheRequest_tmpfile() calls ap_register_cleanup(..., remove_tmpfile, 
...), and remove_tmpfile() very sensibly calls ap_pfclose() before remove().

In fact, I hadn't spotted it yesterday, but Apache::Upload has a 
tempname() method that tells me exactly where the file went!  It is 
indeed cleaned up OK.

That's the good news.

The bad news is that the TEMP_DIR setting that you've just drawn my 
attention to doesn't work as documented, at least on Windows.

In my case, the default temporary directory used was C:\WINDOWS\Temp, 
but when I tried changing it to C:\Temp via that TEMP_DIR setting, I 
found that it made no difference - the uploaded file still got spooled 
into C:\WINDOWS\Temp.

A look at the MS documentation for their implementation of the standard 
C library routine tempnam(), which ApacheRequest_tmpfile() uses, says of 
the first argument, "Target directory to be used if TMP not defined".  
The "TMP" there is a reference to the TMP environment variable.

I had the Apache service running as the LocalSystem account, for which 
TMP is evidently defined as C:\WINDOWS\Temp by the system.  Sure enough, 
if I reconfigure Apache to run as the user "steveh", whose TMP 
environment variable is defined as "C:\DOCUME~1\steveh\LOCALS~1\Temp" 
(again by the system), then the uploaded file now gets spooled into 
there, again ignoring my TEMP_DIR setting.

How does tempnam() behave on other OS's?  My K&R makes no mention of 
environment variables coming into play.

If it's only Windows that behaves this way then I'm happy to provide a 
DOC PATCH to describe this behaviour.

Alternatively, the attached patch fixes it for me.  It works by simply 
clearing the TMP environment variable for the duration of the tempnam() 
call.  Note that it only does that if TEMP_DIR has been set, otherwise 
tempnam() has no directory specified to work with, which makes it 
default to the value of P_tmpdir in <stdio.h>, which is "\\" -- not very 
nice!

- Steve

Mime
View raw message