NetBSD Problem Report #41549

From www@NetBSD.org  Sat Jun  6 05:37:52 2009
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id DEDA163B88A
	for <gnats-bugs@gnats.netbsd.org>; Sat,  6 Jun 2009 05:37:51 +0000 (UTC)
Message-Id: <20090606053751.5DD9263B293@www.NetBSD.org>
Date: Sat,  6 Jun 2009 05:37:51 +0000 (UTC)
From: QFH02545@nifty.com
Reply-To: QFH02545@nifty.com
To: gnats-bugs@NetBSD.org
Subject: Sometimes fcntl(,F_SETLK)'s lock remains after the process exits.
X-Send-Pr-Version: www-1.0

>Number:         41549
>Category:       kern
>Synopsis:       Sometimes fcntl(,F_SETLK)'s lock remains after the process exits.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jun 06 05:40:00 +0000 2009
>Closed-Date:    Mon Jun 08 00:22:54 +0000 2009
>Last-Modified:  Mon Jun 08 00:22:54 +0000 2009
>Originator:     HITOSHI OSADA
>Release:        NetBSD 5.99.13 (2009/06/05)
>Organization:
None
>Environment:
System: NetBSD amd690g 5.99.13 NetBSD 5.99.13 (AMD690G) #3: Thu Jun 4 21:14:26 JST 2009 root@amd690g:/NetBSD-obj/src-obj/sys/arch/amd64/compile/AMD690G amd64
Architecture: x86_64
Machine: amd64

>Description:
 Sometimes fcntl(, F_SETLK, ...)'s lock remains after the process exits.
 The lock remains until the lockfile removed.

 firefox3 sometimes failed as "firefox already exists but not responding".

>How-To-Repeat:

 $ while ./locktest; do ./locktest; done
 (...doing some heavy jobs at background...)
 locktest: Resource temporarily unavailable
 $ ./locktest
 locktest: Resource temporarily unavailable
 $ rm .testlockfile
 $ ./locktest
 $

locktest.c:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

/*
 * Codes from firefox-3.0.10 (nsProfileLock.cpp)
 */
int mLockFileDesc;
int mHaveLock;

int
locktest(const char *filename)
{
  int rv = 0;
  mLockFileDesc = open(filename,
		       O_WRONLY | O_CREAT | O_TRUNC, 0666);
  if (mLockFileDesc != -1)
    {
      struct flock lock;

      lock.l_start = 0;
      lock.l_len = 0; 
      lock.l_type = F_WRLCK;
      lock.l_whence = SEEK_SET;

      struct flock testlock = lock;
      if (fcntl(mLockFileDesc, F_GETLK, &testlock) == -1)
	{
	  close(mLockFileDesc);
	  mLockFileDesc = -1;
	  rv = -1;
	}
      else if (fcntl(mLockFileDesc, F_SETLK, &lock) == -1)
	{
	  close(mLockFileDesc);
	  mLockFileDesc = -1;
	  perror("locktest");
	  if (errno == EAGAIN || errno == EACCES)
	    rv = -2;
	  else
	    rv = -1;
	}
      else
	mHaveLock = 1;
    }
  else
    {
      printf("Failed to open lock file.");
      rv = -1;
    }
  return rv;
}

int
main(void)
{
  return (locktest(".testlockfile") * -1);
}

>Fix:

>Release-Note:

>Audit-Trail:
From: YAMAMOTO Takashi <yamt@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/41549 CVS commit: src/sys/kern
Date: Mon, 8 Jun 2009 00:19:56 +0000

 Module Name:	src
 Committed By:	yamt
 Date:		Mon Jun  8 00:19:56 UTC 2009

 Modified Files:
 	src/sys/kern: kern_descrip.c

 Log Message:
 fd_free: fix posix advisory locks.  PR/41549 from HITOSHI OSADA.


 To generate a diff of this commit:
 cvs rdiff -u -r1.196 -r1.197 src/sys/kern/kern_descrip.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: yamt@NetBSD.org
State-Changed-When: Mon, 08 Jun 2009 00:22:54 +0000
State-Changed-Why:
fixed, thanks.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.