Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 Jun 2000 23:19:09 -0700 (MST)
From:      "Chad R. Larson" <chad@DCFinc.com>
To:        stable@FreeBSD.org
Cc:        William.Bloom@pegsinc.com (Bill Bloom)
Subject:   file locking
Message-ID:  <200006221639.JAA06440@freeway.dcfinc.com>

next in thread | raw e-mail | index | archive | help

--ELM960617949-22199-0_
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

Guys, this seems like a bug, or at least a mis-feature, to me.

If a process locks a region of a file using the POSIX-style locks, a
subsequent attempt to use the BSD flock call to lock the whole file
fails.  This is arguably a silly thing to do, but still...

Reading the red/maroon 4.4BSD internals book seems to imply both
styles of locks should properly interoperate.  Do we believe this is
working as designed?  That is, even though it is the same process ID
attempting to acquire the second lock it fails.

Attached is a test program.  The second lock attempt fails on
2.2.8-STABLE and on 3.4-STABLE (linked against either the threaded
or not threaded libc).  Both locks succeed on Solaris 2.6.  I
haven't tried the program on a Linux system yet.

	-crl
--
Chad R. Larson (CRL15)   602-953-1392   Brother, can you paradigm?
chad@dcfinc.com         chad@larsons.org          larson1@home.net   
DCF, Inc. - 14623 North 49th Place, Scottsdale, Arizona 85254-2207

--ELM960617949-22199-0_
Content-Type: text/x-source
Content-Disposition: attachment; filename=testlock.c
Content-Description: lock interaction test program
Content-Transfer-Encoding: 7bit

/* Test for lock method interactions */

#include <sys/file.h>

main()
{
    struct flock lock_info;
    char	*lockfile="locking";
    int		lock_fd;
    int		ret;

    /* create a test file to be locked */
    if((lock_fd=open(lockfile,O_WRONLY | O_CREAT | O_EXCL,0444)) == -1)
    {
	perror("Can't create file");
	exit(1);
    }

    /* set the range-style lock */
    lock_info.l_type = F_WRLCK;
    lock_info.l_whence = 0;
    lock_info.l_start = 0;
    lock_info.l_len = 0;

    ret = fcntl(lock_fd, F_SETLK, &lock_info);
    if (ret != -1)
	printf("fcntl lock acquired, success code = %d\n", ret);
    else
	perror("failed to acquire fcntl lock");

    /* now try full file lock */
    ret = flock(lock_fd, LOCK_NB | LOCK_EX);
    if (ret != -1)
	printf("flock lock acquired, success code = %d\n", ret);
    else
	perror("failed to acquire flock lock");

    unlink(lockfile);		/* cleanup */
}

--ELM960617949-22199-0_--



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200006221639.JAA06440>