[comp.unix.xenix] Xenix Fcntl locks

david@bdt.UUCP (David Beckemeyer) (04/06/89)

I have a multiuser database application that under Real Unix System V
uses fcntl(2) for file locking.  The code that does the low-level lock is:

    struct flock fb;

    fb.l_type = F_WRLCK;
    fb.l_whence = 0;
    fb.l_start = 0;
    fb.l_len = LOCKREGION;
    if (fcntl(fd, F_SETLK, &fb) == -1)
	return ERROR;
    return OK;

Under System V, the above will either create the lock if the file isn't
already locked, returning zero, or it will fail to create the lock if
the file is already locked (or there is some other error) and return -1.

The SCO Xenix manuals for the AT (286) have the AT&T man page for fcntrl(2)
and they say it works like real System V fcntrl as far as I can tell.  But in
real life under Xenix the above code appears to cause a wait lock as though
I used F_SETLKW.  If the file is locked, under Xenix the process seems to
block until it becomes unlocke, which doesn't happen under System V.

What can I do?  How do applications do file locking under Xenix?  Is there
a more "correct" way?  All I need is low-level exclusive locking without
blocking.
-- 
David Beckemeyer (david@bdt.UUCP)	| "Adios amigos.  And, as they say when 
Beckemeyer Development Tools		| the boys are scratching the bad ones,
478 Santa Clara Ave. Oakland, CA 94610	| 'Stay a long time, Cowboy!'"
UUCP: {uunet,ucbvax}!unisoft!bdt!david	|                  - Jo Mora