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

 
 

bug #30530: Usage of tmpfile()

Submitted by:  None
Submitted on:  Fri 23 Jul 2010 02:46:36 PM UTC  
 
Category: Compilation/PortabilitySeverity: 3 - Ordinary
Status: FixedAssigned to: None
Open/Closed: ClosedRelease: None
Effort: 0.00

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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

I pushed a fix.

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

I'm working on this.

Ben Pfaff <blp>
Project 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>
Project 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>
Project 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 File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 7 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 30 Jul 2010 05:47:01 AM UTCblpCategoryOther=>Compilation/Portability
      StatusIn Progress=>Fixed
      Open/ClosedOpen=>Closed
    Fri 30 Jul 2010 04:09:07 AM UTCblpStatusConfirmed=>In Progress
    Sat 24 Jul 2010 06:09:32 AM UTCjmdCategorySystem/Portable File I/O=>Other
      Severity5 - Average=>3 - Ordinary
      StatusNone=>Confirmed

    Back to the top


    Powered by Savane 3.1-cleanup1