Mail Archives: cygwin/2009/07/22/11:27:39
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 -