Thread View: comp.bugs.sys5
5 messages
5 total messages
Started by Frank Glass
Mon, 07 Nov 1988 22:11
O_EXCL flag on open of character tty device.
Author: Frank Glass
Date: Mon, 07 Nov 1988 22:11
Date: Mon, 07 Nov 1988 22:11
37 lines
1528 bytes
1528 bytes
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?
--------------------cut here----------------------------
#include <termio.h>
#include <fcntl.h>
#include <stdio.h>
main(argc,argv)
{
int ii;
char *tty_id = "/dev/tty00"; /* arbitrary tty choice */
ii = open(tty_id,O_WRONLY|O_NDELAY|O_EXCL);
if(ii<0) {
fprintf(stderr,"First open attempt, ");
perror(tty_id);
exit(1);
}
ii = open(tty_id,O_WRONLY|O_NDELAY|O_EXCL);
if(ii<0) {
fprintf(stderr,"Second open attempt, ");
perror(tty_id);
exit(1);
}
fprintf(stderr,"Opened %s with no errors, O_EXCL a mystery.\n",tty_id);
}
--
Frank Glass
Holos Software, Inc.
Voice: (404) 496-1358
UUCP: ...!gatech!holos0!fsg
Re: O_EXCL flag on open of character tty device.
Author: Guy Harris
Date: Tue, 08 Nov 1988 18:19
Date: Tue, 08 Nov 1988 18:19
16 lines
888 bytes
888 bytes
> My understanding from the manuals is that the O_EXCL flag can >be used to exclusively open a device. That's not what its original intent was; it was an "exclusive create" flag, not an "exclusive-use" open flag - it said that if 1) O_CREAT was also set and 2) the file already existed the "open" should fail, returning -1 and setting "errno" to EEXIST. Some vendors may have made some of their device drivers interpret it as an exclusive-use "open", but this is not guaranteed to work everywhere.
Re: O_EXCL flag on open of character tty device.
Author: Dan Mercer
Date: Tue, 08 Nov 1988 19:28
Date: Tue, 08 Nov 1988 19:28
44 lines
1837 bytes
1837 bytes
In article <1464@holos0.UUCP> fsg@holos0.UUCP (Frank Glass) writes:
:
: 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?
:
:--------------------cut here----------------------------
:#include <termio.h>
:#include <fcntl.h>
:#include <stdio.h>
:main(argc,argv)
:{
: int ii;
: char *tty_id = "/dev/tty00"; /* arbitrary tty choice */
:
: ii = open(tty_id,O_WRONLY|O_NDELAY|O_EXCL);
: if(ii<0) {
: fprintf(stderr,"First open attempt, ");
: perror(tty_id);
: exit(1);
: }
: ii = open(tty_id,O_WRONLY|O_NDELAY|O_EXCL);
: if(ii<0) {
: fprintf(stderr,"Second open attempt, ");
: perror(tty_id);
: exit(1);
: }
: fprintf(stderr,"Opened %s with no errors, O_EXCL a mystery.\n",tty_id);
:}
:--
:Frank Glass
:Holos Software, Inc.
:Voice: (404) 496-1358
:UUCP: ...!gatech!holos0!fsg
Don't be fooled by the term exclusive. The only documentation I found
indicates that the flag must be used with O_CREAT, and failure depends
not on whether the file is open, but whether it already exists.
Dan Mercer
NCR Comten
Re: O_EXCL flag on open of character tty device.
Author: Mike Wescott
Date: Tue, 08 Nov 1988 21:52
Date: Tue, 08 Nov 1988 21:52
15 lines
918 bytes
918 bytes
In article <1464@holos0.UUCP> fsg@holos0.UUCP (Frank Glass) writes: > > My understanding from the manuals is that the O_EXCL flag can > be used to exclusively open a device. Nope. The man page says: O_EXCL If O_EXCL and O_CREAT are set, the function open will fail if the file exists. It does give you a chance to create a new file and know that you didn't clobber anything. -- -Mike Wescott mike.wescott@ncrcae.Columbia.NCR.COM
Re: O_EXCL flag on open of character tty device.
Author: Brandon S. Allbery
Date: Mon, 14 Nov 1988 22:53
Date: Mon, 14 Nov 1988 22:53
32 lines
2172 bytes
2172 bytes
As quoted from <1464@holos0.UUCP> by fsg@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@hal.cwru.edu
allberyb@skybridge.sdi.cwru.edu <ALSO> allbery@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>.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads