/tmp versus temporary file types

der Mouse mouse at mcgill-vision.UUCP
Tue Sep 3 17:51:13 AEST 1985


[paraphrasing]
> ....like to see some discussion on: /tmp.
> ....anybody can 'rm /tmp/*', read files there, etc....

Anyone can rm /tmp/*, true.  Read on.
Anyone can read files there only if the program which creates them gives
them  a mode which allows  read  access.   Usually if you umask  007  or
anything ending in a 7 then world cannot access to files you create.

     When I write something which wants a temporary  file I do something
like this:

	/* generate temporary filename via mktemp() or some such */
	/* temporary filename in tmpfn */
	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);
	/* now the temporary file sticks around on disk as long as I have */
	/* it open, but is COMPLETELY inaccessible except to this process */
	/* and any children I fork */

     Granted, this does not work  when  you want another program to read
the file by name.    Just another reason to  make  everything work as  a
filter  (:-).  This sort of code has proven useful  in several  programs
which  merely want someplace  to  put huge (>  max  malloc()able  space)
amounts of temporary data.
-- 
					der Mouse

{ihnp4,decvax,akgua,etc}!utcsri!mcgill-vision!mouse
philabs!micomvax!musocs!mcgill-vision!mouse

Hacker: One responsible for destroying /
Wizard: One responsible for recovering it afterward



More information about the Comp.unix.wizards mailing list