From owner-freebsd-stable Thu Jun 22 9:39:43 2000 Delivered-To: freebsd-stable@freebsd.org Received: from freeway.dcfinc.com (cx74889-a.phnx3.az.home.com [24.1.193.157]) by hub.freebsd.org (Postfix) with ESMTP id F24E837C329 for ; Thu, 22 Jun 2000 09:39:37 -0700 (PDT) (envelope-from chad@freeway.dcfinc.com) Received: (from chad@localhost) by freeway.dcfinc.com (8.8.8/8.8.8) id JAA06440 for stable@FreeBSD.org; Thu, 22 Jun 2000 09:39:36 -0700 (MST) (envelope-from chad) From: "Chad R. Larson" Message-Id: <200006221639.JAA06440@freeway.dcfinc.com> Subject: file locking To: stable@FreeBSD.org Date: Fri, 9 Jun 2000 23:19:09 -0700 (MST) Cc: William.Bloom@pegsinc.com (Bill Bloom) Reply-To: chad@DCFinc.com X-Mailer: ELM [version 2.4ME+ PL40 (25)] MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=ELM960617949-22199-0_ Content-Transfer-Encoding: 7bit Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG --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 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