EXCL without CREAT

Henry Spencer henry at utzoo.UUCP
Fri Dec 13 06:59:43 AEST 1985


>	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()?



More information about the Comp.unix.wizards mailing list