Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: net.bugs.4bsd,net.unix-wizards Subject: EXCL without CREAT Message-ID: <6220@utzoo.UUCP> Date: Thu, 12-Dec-85 15:59:43 EST Article-I.D.: utzoo.6220 Posted: Thu Dec 12 15:59:43 1985 Date-Received: Thu, 12-Dec-85 15:59:43 EST References: <5507@allegra.UUCP> Organization: U of Toronto Zoology Lines: 24 > It is most unfortunate that open() flag O_EXCL only applies > when O_CREAT is also in effect. If there were a flag that > meant ``succeed only if you can get me the file with nobody > else having it opened, and nobody else able to open it,'' > then that atomic operation could have been used here. > ...Such a mechanism > would save a lot of misguided hacking to achieve exclusive > use of a resource. It would also create problems of its own. Consider the following: main() { int foo; foo = open("/etc/passwd", O_READ|O_EXCL); for (;;) sleep(30000); } The CREAT-only restriction is there for a reason. In any case, removing this limitation (assuming that the security problems could be solved) would amount to re-inventing flock(); why not just add an advisory/mandatory flag to flock()?