O_EXCL flag on open of character tty device.

Frank Glass fsg at holos0.UUCP
Tue Nov 8 08:11:44 AEST 1988


	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



More information about the Comp.bugs.sys5 mailing list