delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/07/22/11:27:39

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_72,J_CHICKENPOX_82,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS
X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Eric Blake <ebb9 AT byu DOT net>
Subject: Re: flock still buggy
Date: Wed, 22 Jul 2009 15:27:07 +0000 (UTC)
Lines: 82
Message-ID: <loom.20090722T151319-66@post.gmane.org>
References: <loom DOT 20090721T231647-613 AT post DOT gmane DOT org> <20090722100804 DOT GF27613 AT calimero DOT vinschen DOT de> <loom DOT 20090722T143408-726 AT post DOT gmane DOT org> <20090722150048 DOT GK27613 AT calimero DOT vinschen DOT de>
Mime-Version: 1.0
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Corinna Vinschen <corinna-cygwin <at> cygwin.com> writes:

> > $ ./foo 4& sleep 2; ./foo 0
> > 
> > Oops - process 14060 got the lock before 12692 and 21704 exited.
> 
> This looks different with my patch:
> 

Yep, so far, it looks like your patch follows the semantics I expect for every 
one of my tests (the lock remains until explicitly unlocked, or until all 
handles are closed, whether by explicit close, process exit, or close-on-
exec).  And the original autoconf question which raised this issue in the first 
place now passes.

I'm not sure whether there are lurking bugs in fcntl/lockf locking, but I think 
we've finally nailed the last of the flock bugs.

> > Oops - process 26264 successfully unlocked fd, even though it was marked 
close-
> > on-exec by 10932 before the fork.
> 
> Well, sure, it has been marked close-on-exec, but this doesn't mean
> the descriptor is invalid after the fork.  AFAICS it's perfectly
> valid for the forked child 26264 to unlock the BSD lock.  What am
> I missing?

Nothing.  I guess I wasn't thinking straight on this case - a fork is not the 
same as exec, and I validated that even without your patch, flock(LOCK_UN) 
fails on closed fd, and close-on-exec does close the fd when I actually get to 
the exec.

By the way, your posted patch missed out on fhandler.cc; I assume this is what 
you meant:

diff --git i/winsup/cygwin/fhandler.cc w/winsup/cygwin/fhandler.cc
index ffbd02f..ade2c6e 100644
--- i/winsup/cygwin/fhandler.cc
+++ w/winsup/cygwin/fhandler.cc
@@ -1,7 +1,7 @@
 /* fhandler.cc.  See console.cc for fhandler_console functions.

    Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-   2005, 2006, 2007, 2008 Red Hat, Inc.
+   2005, 2006, 2007, 2008, 2009 Red Hat, Inc.

 This file is part of Cygwin.

@@ -1034,7 +1034,7 @@ fhandler_base::close ()
   /* Delete all POSIX locks on the file.  Delete all flock locks on the
      file if this is the last reference to this file. */
   if (unique_id)
-    del_my_locks (false);
+    del_my_locks (after_close);
   if (nohandle () || CloseHandle (get_handle ()))
     res = 0;
   else
@@ -1359,7 +1359,7 @@ fhandler_base::fixup_after_fork (HANDLE parent)
     setup_overlapped ();
   /* POSIX locks are not inherited across fork. */
   if (unique_id)
-    del_my_locks (true);
+    del_my_locks (after_fork);
 }

 void
@@ -1369,7 +1369,7 @@ fhandler_base::fixup_after_exec ()
   if (get_overlapped ())
     setup_overlapped ();
   if (unique_id && close_on_exec ())
-    del_my_locks (false);
+    del_my_locks (after_exec);
 }

 bool


-- 
Eric Blake





--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019