Sun NFS file locking

David Beckemeyer david at bdt.com
Fri Jun 28 06:22:00 AEST 1991


I have a network application which must be able to obtain exclusive
access to a file.   Following the Sun manuals, I'm using hte fcntl()
system call, as follows:

        /* Use fcntl to lock the master control file */
        sprintf(tmpnam, "%s/LOCKCTL", dir);
        lckfd = open(tmpnam, 2);
        if (lckfd < 0)
                return(seterror("mklock: cannot open LOCKCTL"));
        /* lock the whole file for exclusive use */
        lck.l_type = F_WRLCK;
        lck.l_whence = 0;
        lck.l_start = 0;
        lck.l_len = 0;
        if (fcntl(lckfd, F_SETLK, &lck)) {
                close(lckfd);
                return(seterror("mklock: F_SETLK failed"));
        }

The problems are that sometimes a process will hang in the
fcntl() call; ps reports that the process is in the D state
and the WCHAN is "socket".   What is going on?   It seems
like the rcp.lockd process gets confused under certain
circumstances.   What makes this happen and how does one
avoid it?  Is there a reliable way to lock files over the
network with SunOS?
-- 
David Beckemeyer (david at bdt.COM)	| "Lester Moore - Four slugs from a .44
Beckemeyer Development Tools		|  no Les, no more."
P.O. Box 21575, Oakland, CA 94620	|   - Headstone at Boot Hill
UUCP: {uunet,ucbvax}!unisoft!bdt!david	|     Tombstone, AZ




More information about the Comp.sys.sun mailing list