Op 07-11-16 om 13:45 schreef Stephane Chazelas: > 2016-11-02 13:32:44 +0000, Martijn Dekker: > [...] >> > If both 'mkdir' and 'ln' operate atomically, there could be a safe >> > workaround for creating a regular file directly under /tmp. It would >> > involve creating a (very) temporary directory under /tmp using 'mkdir >> > -m700', then creating the file inside there, setting the mode, etc. with >> > no need for atomicity, then attempting to 'ln' that file back to /tmp >> > until we've got an available name. Do you think this could work? > [...] > > I don't think you can use ln here. > > ln "$tempdir/file" "$tempfile" > > would create a "$tempfile/file" link if "$tempfile" existed and > was of type directory or a symlink eventually resolving to a > directory.
...and it's not as if I didn't know that either. Sorry for generating useless noise here. I let the details blind me to the obvious. > You could use "link" (Unix, not POSIX), or "ln -T" (GNU, not > POSIX) or "mv -Tn" (GNU) instead. "link" seems good. It's on AIX (according to ibm.com), on anything using GNU coreutils, on the Mac, on FreeBSD, NetBSD, and Solaris 13. And I've confirmed for all of these but AIX that it can be invoked by a regular user. But it's not on OpenBSD. Drat. :/ GNU "ln -T" or GNU "mv -Tn" won't help me as "link" and "ln" are both part of the same GNU coreutils package. The current OpenBSD release version has m4 with mkstemp() (thanks for pointing that out earlier, Geoff -- I hadn't discovered that yet), so between those and "link" it should hopefully be covered. I could even fall back on OS implementations of "mktemp" which are also fairly ubiquitous. This is going to need a feature test. Since m4 with mkstemp() is POSIX, it should be preferred. Well, back to work. Thanks, - M.
