bugPSPP - Bugs: bug #30530, Usage of tmpfile()

 
 

bug #30530: Usage of tmpfile()

Submitter:  None
Submitted:  Fri 23 Jul 2010 02:46:36 PM UTC
   
 
Category:  Compilation/Portability Severity:  3 - Ordinary
Status:  Fixed Assigned to:  None
Open/Closed:  Closed Release:  None
Effort:  0.00
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 30 Jul 2010 05:47:01 AM UTC, comment #4: 

I pushed a fix.

Ben Pfaff <blp>
Group administrator
Fri 30 Jul 2010 04:09:07 AM UTC, comment #3: 

I'm working on this.

Ben Pfaff <blp>
Group administrator
Mon 26 Jul 2010 08:21:10 PM UTC, comment #2: 

tmpfile() doesn't respect TMPDIR even with glibc (according to jmd's testing).  Let's invent a new interface that does.

Ben Pfaff <blp>
Group administrator
Sat 24 Jul 2010 06:09:32 AM UTC, comment #1: 

I agree it's not very satisfactory if TMPDIR works in certain situations but not in others.

We use the tmpfile replacement from gnulib, so portability, at least in theory, is not a problem.  However it looks as if gnulib directly calls the system's tmpfile if available otherwise (ie on windows) generates its own.

I think we should ask the gnulib team to change their tmpfile so that it respects the TMPDIR variable.  If they can't or won't, then I agree, we should use a different function.

John Darrington <jmd>
Group administrator
Fri 23 Jul 2010 02:46:36 PM UTC, original submission:  

Note: I originally posted this bug on bug-gnu-pspp but I got no reply.


The PSPP command line binary may create a few temporary files during data processing.
As far as I can see, pspp uses the TMPDIR environment variable (it uses getenv("TMPDIR") and uses the result when available) to determine the directory for temporary files. That means the directory for temporary files can be configured at runtime when invoking the pspp binary.
This is fine, however, I think pspp also uses the POSIX tmpfile() call in some cases. tmpfile() does not seem to use the TMPDIR environment variable and as far as I can see it is not fully portable nor is its result predictable.

The tmpfile man page says:
"The standard does not specify the directory that tmpfile() will use. Glibc will try the path prefix P_tmpdir defined in <stdio.h>, and if that fails the directory /tmp.".

P_tmpdir is a compile time definition whereas reading an environment variable is a runtime configuration.

P_tmpdir defaults to "/tmp" in my enviroment (which is the system's temporary directory). That means pspp will create a few temporary files in /tmp, however, it creates several other files in /opt/pdp/tmp (which is the directory specified using the $TMPDIR environment variable).
That means when invoking pspp from the command line the temporary files may go to two different directories which is not very good when trying to control, monitor, and limit disk usage.

While tmpfile() is definitely convenient to use in the code, I think the calls should be changed to use some procedure that uses the TMPDIR environment variable (when available) and creates the temporary files there. Additionally, the temporary files would need to be removed when not required anymore.
tmpfile() does that automatically but any other procedures won't.

In pspp-0.6.1, I found the following usages of tmpfile():

src/data/case-tmpfile.c:54:  ctf->file = tmpfile ();
src/libpspp/pool.c:754:  FILE *file = tmpfile ();  
src/output/postscript.c:1096: ch->file = tmpfile ();

I saw there is a more recent version of pspp already, however, the newer version still uses tmpfile().
Do you think the tmpfile() calls can be changed?

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by blp (Posted a comment)
  • -email is unavailable- added by jmd (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2010-07-30 blp CategoryOther Compilation/Portability
        StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2010-07-30 blp StatusConfirmed In Progress
    2010-07-24 jmd CategorySystem/Portable File I/O Other
        Severity5 - Average 3 - Ordinary
        StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code