* flock.cc: Clarify a couple of comments.

(lf_setlock): Treat not being able to sync on a process as a potential
	deadlock situation.  Close process handle using CloseHandle.
This commit is contained in:
Corinna Vinschen 2008-03-24 15:36:17 +00:00
parent 7f25a29df4
commit b9e2579c0f
2 changed files with 20 additions and 7 deletions

View File

@ -1,3 +1,9 @@
2008-03-24 Corinna Vinschen <corinna@vinschen.de>
* flock.cc: Clarify a couple of comments.
(lf_setlock): Treat not being able to sync on a process as a potential
deadlock situation. Close process handle using CloseHandle.
2008-03-24 Corinna Vinschen <corinna@vinschen.de> 2008-03-24 Corinna Vinschen <corinna@vinschen.de>
* flock.cc: Fix typo in comment. * flock.cc: Fix typo in comment.

View File

@ -159,9 +159,9 @@ static NO_COPY muto lockf_guard;
#define LOCK_OBJ_NAME_LEN 56 #define LOCK_OBJ_NAME_LEN 56
/* This function takes the own process security descriptor DACL and adds /* This function takes the own process security descriptor DACL and adds
SYNCHRONIZE permissions for everyone. This allows to wait any process SYNCHRONIZE permissions for everyone. This allows all processes
to wait for this process to set the event object to signalled in case to wait for this process to die when blocking in a F_SETLKW on a lock
the lock gets removed or replaced. */ which is hold by this process. */
static void static void
allow_others_to_sync () allow_others_to_sync ()
{ {
@ -751,7 +751,7 @@ fhandler_disk_file::lock (int a_op, struct __flock64 *fl)
need_fork_fixup (true); need_fork_fixup (true);
} }
/* Unlock the fd table which has been locked in fcntl_worker, otherwise /* Unlock the fd table which has been locked in fcntl_worker, otherwise
a F_SETLKW waits forever... */ a blocking F_SETLKW never wakes up on a signal. */
cygheap->fdtab.unlock (); cygheap->fdtab.unlock ();
lockf_t **head = &node->i_lockf; lockf_t **head = &node->i_lockf;
@ -886,19 +886,26 @@ lf_setlock (lockf_t *lock, inode_t *node, lockf_t **clean)
* Add our lock to the blocked list and sleep until we're free. * Add our lock to the blocked list and sleep until we're free.
* Remember who blocked us (for deadlock detection). * Remember who blocked us (for deadlock detection).
*/ */
/* TODO */ /* FIXME? See deadlock recognition above. */
/* Wait for the blocking object and its holding process. */ /* Wait for the blocking object and its holding process. */
HANDLE obj = block->open_lock_obj (); HANDLE obj = block->open_lock_obj ();
HANDLE proc = OpenProcess (SYNCHRONIZE, FALSE, block->lf_wid); HANDLE proc = OpenProcess (SYNCHRONIZE, FALSE, block->lf_wid);
if (!proc) if (!proc)
api_fatal ("OpenProcess: %E"); {
/* If we can't synchronize on the process holding the lock,
we will never recognize when the lock has been abandoned.
Treat this as a deadlock-like situation for now. */
debug_printf ("OpenProcess: %E");
NtClose (obj);
return EDEADLK;
}
HANDLE w4[3] = { obj, proc, signal_arrived }; HANDLE w4[3] = { obj, proc, signal_arrived };
node->del_all_locks_list (); node->del_all_locks_list ();
//SetThreadPriority (GetCurrentThread (), priority); //SetThreadPriority (GetCurrentThread (), priority);
node->UNLOCK (); node->UNLOCK ();
DWORD ret = WaitForMultipleObjects (3, w4, FALSE, INFINITE); DWORD ret = WaitForMultipleObjects (3, w4, FALSE, INFINITE);
NtClose (proc); CloseHandle (proc);
NtClose (obj); NtClose (obj);
node->LOCK (); node->LOCK ();
//SetThreadPriority (GetCurrentThread (), old_prio); //SetThreadPriority (GetCurrentThread (), old_prio);