Jim Lesurf writes:
Richard Kettlewell wrote:
If your goal is to avoid physical writes if possible, then a tmpfs is a
good bet.
Is that something I can expect anyone who used my programs to either
already have, or be happy to setup?
A common configuration is for /tmp to be a tmpfs. People who don’t make
it a tmpfs presumably don’t care... Put another way there’s a limit to
how much policy your program should be setting; rather, it should be
following the user’s policy.
There are some things to get right if using /tmp.
1. If the environment variable TMPDIR is set, use that instead of /tmp.
2. Don’t use predictable filenames; /tmp is shared between multiple
users. (Get this wrong and you will introduce security problems.)
If you don’t care about the filename, the easiest policy is to use
tmpfile(). That’ll given you an anonymous file somewhere sensible.
If you do care about the filename, use mkstemp().
To expand on that: I just checked my (Mint) laptop and it does have a
tempfs set up for /run. And inside that I find, for example,
/run/usr/1000 directory that presumably for tempfiles associated with
things being run already for me as user 1000. I can create files, etc,
in that when operating as myself, so don't need to be root. Seems OK
for me.
/run isn’t really the right place for application temporary files.
--
http://www.greenend.org.uk/rjk/