Rainer Weikusat <rweikusat@talktalk.net> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
Nicolas George <nicolas$george@salle-s.org> writes: >>>>Muttley@dastardlyhq.com, dans le message <v36kd8$11r1b$1@dont-email.me>, >>>> a écrit :
The simple answer being that no process uses /tmp unless it needs to share
data with another via files.
So where should they put their temporary files?
$ mkdir ${TMPDIR}/${LOGNAME} && chown 1700 ${TMPDIR}/${LOGNAME}
Note that /tmp and /var/tmp usually have the "Sticky" mode bit
set which limits the operations that a non-owner can
perform on a file in that directory.
This solves only half of the problem: mkdir will fail if the given
filesystem name already exists. Some scheme to create unguessable names
and try using them until success would still be needed on top of that.
`mkdir -p` solves that part of the problem.
But what if somebody else
has created a directory whose name happens to match your ${LOGNAME}?
It's a convention that works only if everyone follows it.
As Scott Lurndal points out, this is what mktemp(1) is for.
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
Rainer Weikusat <rweikusat@talktalk.net> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
Nicolas George <nicolas$george@salle-s.org> writes: >>>>>Muttley@dastardlyhq.com, dans le message <v36kd8$11r1b$1@dont-email.me>, >>>>> a écrit :
The simple answer being that no process uses /tmp unless it needs to share
data with another via files.
So where should they put their temporary files?
$ mkdir ${TMPDIR}/${LOGNAME} && chown 1700 ${TMPDIR}/${LOGNAME}
Note that /tmp and /var/tmp usually have the "Sticky" mode bit
set which limits the operations that a non-owner can
perform on a file in that directory.
This solves only half of the problem: mkdir will fail if the given
filesystem name already exists. Some scheme to create unguessable names
and try using them until success would still be needed on top of that.
`mkdir -p` solves that part of the problem.
That's not a problem. It's an important featue of a partial solution.
But what if somebody else
has created a directory whose name happens to match your ${LOGNAME}?
It's a convention that works only if everyone follows it.
As Scott Lurndal points out, this is what mktemp(1) is for.
Or mkstemp or tmpfile. On Linux (since 3.11), there's also an O_TMPFILE
open flag which creates a namless open file in some directory (passed as >pathname argument to open). It's also not really complicated to do this
with plain open:
1. Generate a 'hard to guess' name
2. Try opening with O_CREAT | O_EXCL
3. Success? => return fd
4. goto 1
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 493 |
Nodes: | 16 (2 / 14) |
Uptime: | 191:33:24 |
Calls: | 9,707 |
Calls today: | 2 |
Files: | 13,740 |
Messages: | 6,180,053 |