/tmp versus temporary file types

Rob McMahon cudcv at daisy.warwick.UUCP
Sat Sep 14 01:54:23 AEST 1985


In article <136 at mcgill-vision.UUCP> mouse at mcgill-vision.UUCP (der Mouse) writes:
>> ....like to see some discussion on: /tmp.
>> ....anybody can 'rm /tmp/*', read files there, etc....
>
>	unlink(tempfn); /* in case a file by that name already exists */
>	fd = open(tempfn,O_CREAT|O_TRUNC|O_RDWR,0644);
>	/* O_RDWR and 0644 are variable depending on the application */
>	unlink(tempfn);

I have always felt this was a mess.  How about an O_TEMP option to open, so
that you can do something like

        fd = open(dirname, O_TEMP);

to atomically create and unlink a file on the same filesystem as dirname if
the user has write permission to the directory dirname.  This would save
having to guess a unique name, checking to see if the name already existed,
leaving files around if the program or system crashed between the open and the
unlink, people accidentally removing other peoples temporary files (I get
people coming to me saying "but I didn't think the system would let me remove
other peoples files", having destroyed half a dozen peoples long troff jobs
running in the background).

A new system call

        flink(fd, name, mode) char *name;

would be useful too, so that a link could be created for an open temporary
file.  This would save file transfer programs, for example, having to create a
temporary file on the same file system, which it leaves around if it fails (or
worse yet overwrite the existing file before it knows whether the transfer
will succeed.  Daemons wouldn't have to create files tf... and change them to
cf... later.

Doesn't this seem like a cleaner way of working ?  I look at my /tmp
filesystem which is normally 2% full, but occasionally overflows with
disasterous consequences, and I cringe.  Maybe we could do away with those
        find /tmp -mtime +1 -exec rm -f {} \;
things in /etc/rc and crontab ?  Any thoughts ...

Rob McMahon, Computer Unit, Warwick University, Coventry, England
UUCP: ..!mcvax!ukc!warwick!cudcv



More information about the Comp.unix.wizards mailing list