On Sat, Apr 18, 2020 at 12:01:37AM +0700, Robert Elz wrote: > Date: Fri, 17 Apr 2020 18:15:01 +0200 > From: Joerg Sonnenberger <jo...@bec.de> > Message-ID: <20200417161501.gb72...@bec.de> > > | I'm talking about the difference between this new clobber flag and > | O_EXCL. > > OK. > > | As in: why doesn't the noclobber flag just set O_EXCL and done. > > That's largely what it does these days, but it doesn't work. > > | As in: it seems reasonable to me to just do the > | device check afterwards, > > That's exactly what is generally done. But that leaves race > conditions, and is possible to defeat. > > If all that matters is noclobber mode as originally intended, there > is no genuine problem, and no-one would have ever considered any of this, > > The problem is that the world (or some section of it) has apparently > decided that noclobber mode ought to work for reliably doing sh > level locking primitives (as in, critical regions, etc). For that, > race conditions such that things sometimes fail are unacceptable. > And "generally not" doesn't work at the level that matters.
I don't understand this argument. I would invert the logic in /bin/sh, e.g. try to open with O_CREAT|O_EXCL first and only do the open dance if it fails with EEXIST. That would give it reasonable behavior even for lock files? Joerg