Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site mcgill-vision.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!bbnccv!bbncca!linus!philabs!micomvax!musocs!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP (der Mouse) Newsgroups: net.unix-wizards Subject: /tmp versus temporary file types Message-ID: <136@mcgill-vision.UUCP> Date: Tue, 3-Sep-85 03:51:13 EDT Article-I.D.: mcgill-v.136 Posted: Tue Sep 3 03:51:13 1985 Date-Received: Sat, 7-Sep-85 05:52:49 EDT Organization: McGill University, Montreal Lines: 35 [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