O_EXCL flag on open of character tty device.

Brandon S. Allbery allbery at ncoast.UUCP
Tue Nov 15 08:53:38 AEST 1988


As quoted from <1464 at holos0.UUCP> by fsg at holos0.UUCP (Frank Glass):
+---------------
| 	My understanding from the manuals is that the O_EXCL flag can
| be used to exclusively open a device.  The following code works
| as I expect on an AT&T 6386 in that the first open fails if a process
| (like getty, for example) has tty00 open, otherwise the second open
| fails.  Contrary to my expectation, _both_ opens succeed on the 3b2,
| the NCR Tower, and a variety of other System V things.  Do I not
| understand the documentation?
+---------------

Unless O_EXCL has undergone considerable revision since System V Release 2,
you've got a misunderstanding.

(1) O_EXCL only works with O_CREAT; it is ignored otherwise.
(2) Its function is to insure that a file does NOT exist before its creation.
    This is used to allow for atomic lockfile creation:  there is no window
    of vulnerability between the check for the file's existence and its
    creation, so no race condition can result in two or more processes
    creating the file at the same time.

It is possible that System V.3.2 has decided to overload O_EXCL to mean the
same thing as BSD's TIOCEXCL, i.e. exclusive use of a tty device.  But I'm
almost certain that the 3b2 and NCR Tower have the original semantics.

++Brandon
-- 
Brandon S. Allbery, comp.sources.misc moderator and one admin of ncoast PA UN*X
uunet!hal.cwru.edu!ncoast!allbery  <PREFERRED!>	    ncoast!allbery at hal.cwru.edu
allberyb at skybridge.sdi.cwru.edu	      <ALSO>		   allbery at uunet.uu.net
comp.sources.misc is moving off ncoast -- please do NOT send submissions direct
      Send comp.sources.misc submissions to comp-sources-misc@<backbone>.



More information about the Comp.bugs.sys5 mailing list