From owner-freebsd-bugs Mon Nov 19 1:22:16 2001 Delivered-To: freebsd-bugs@freebsd.org Received: from relay1.macomnet.ru (relay1.macomnet.ru [195.128.64.10]) by hub.freebsd.org (Postfix) with ESMTP id 111A237B417; Mon, 19 Nov 2001 01:22:11 -0800 (PST) Received: from news1.macomnet.ru (maxim@news1.macomnet.ru [195.128.64.14]) by relay1.macomnet.ru (8.11.3/8.11.3) with ESMTP id fAJ9Lu7335992; Mon, 19 Nov 2001 12:21:57 +0300 (MSK) Date: Mon, 19 Nov 2001 12:21:56 +0300 (MSK) From: Maxim Konovalov To: Andrey Simonenko Cc: iedowse@FreeBSD.ORG, Subject: Re: kern/23353: fcntl(F_GETLK) return l_pid equal to -1 for the file loked with flock() In-Reply-To: <20011118233624.H62085-100000@lion.com.ua> Message-ID: <20011119110731.W52791-100000@news1.macomnet.ru> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org Hello, On Sun, 18 Nov 2001, Andrey Simonenko wrote: > On Sun, 18 Nov 2001 iedowse@FreeBSD.org wrote: > [...] > > Can this be closed? In the audit-trail it is suggested that this is > > expected behaviour. > > > > May be my bug report isn't really a bug, but a message from Maxim didn't > make me think so. I know that in one case locks are inhereted by childs, > and in other case they aren't. The original my bug report was about > another thing. In the fcntl(2) manual page we can read that: "Note that > flock(2) and fcntl(2) locks can be safely used concurrently". And this > works. And if I locked some file with flock(2), then fcntl(F_GETLK) call > in some another process can tell me that that file is locked. But l_pid > field in the flock structure always is equal to -1 if file is locked with OK, just imagine a process got a lock by flock(2) and then fork(2)ed nine children, so we have ten processes with the same lock. What do you expect to find in flock.l_pid now? Imho l_pid is about clueless here because of the lock inheritance. Historically, flock(2) is a BSD interface and fcntl(F_???LK) is a POSIX one. They can be used concurrently for locking but there is a feature which I described above. Take a look at the line 517 kern_lockf.c (1.25): if (block->lf_flags & F_POSIX) fl->l_pid = ((struct proc *)(block->lf_id))->p_pid; else fl->l_pid = -1; > flock(2) call (at least in my experiments). Also I haven't find any > information about this in manual pages. Agree. What about this patch for fcntl.2: Index: fcntl.2 =================================================================== RCS file: /vol0/cvs/ncvs/src/lib/libc/sys/fcntl.2,v retrieving revision 1.35 diff -u -r1.35 fcntl.2 --- fcntl.2 2001/10/26 17:38:20 1.35 +++ fcntl.2 2001/11/19 09:18:09 @@ -535,6 +535,12 @@ .Xr sigvec 2 , .Xr tcgetpgrp 3 , .Xr tcsetpgrp 3 +.Sh BUGS +fcntl(F_GETLK) returns -1 in +.Fa l_pid +if the process holding a blocking lock previously locked the +file desriptor by +.Xr flock 2 . .Sh HISTORY The .Fn fcntl - -maxim -- Maxim Konovalov, MAcomnet, Internet-Intranet Dept., system engineer phone: +7 (095) 796-9079, mailto: maxim@macomnet.ru To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message