O_EXCL flag on open of character tty device.

Dan Mercer mercer at ncrcce.StPaul.NCR.COM
Wed Nov 9 05:28:11 AEST 1988


In article <1464 at holos0.UUCP> fsg at 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



More information about the Comp.bugs.sys5 mailing list