* cygheap.h (cygheap_debug::endh): Delete.
* debug.cc (lock_debug::acquired): Delete. (lock_debug::lock_debug): Simplify. (lock_debug::unlock): Ditto. (find_handle): Don't set endh here. (add_handle): Add new handle to beginning of the list rather than trying to maintain an end list pointer. (delete_handle): Minor optimization. (mark_closed): Make logic clearer. (verify_handle): Lock handle list before scanning. (setclexec): Ditto. (modify_handle): Ditto. (newh): Don't lock handle list here. Assume caller did this. (mark_closed): Ditto. (close_handle): Remove unneeded #if. * dtable.cc (dtable::dup2): Tweak debug output.
This commit is contained in:
parent
7f01964f06
commit
a99345591f
|
@ -1,3 +1,22 @@
|
|||
2009-08-05 Christopher Faylor <me+cygwin@cgf.cx>
|
||||
|
||||
* cygheap.h (cygheap_debug::endh): Delete.
|
||||
* debug.cc (lock_debug::acquired): Delete.
|
||||
(lock_debug::lock_debug): Simplify.
|
||||
(lock_debug::unlock): Ditto.
|
||||
(find_handle): Don't set endh here.
|
||||
(add_handle): Add new handle to beginning of the list rather than
|
||||
trying to maintain an end list pointer.
|
||||
(delete_handle): Minor optimization.
|
||||
(mark_closed): Make logic clearer.
|
||||
(verify_handle): Lock handle list before scanning.
|
||||
(setclexec): Ditto.
|
||||
(modify_handle): Ditto.
|
||||
(newh): Don't lock handle list here. Assume caller did this.
|
||||
(mark_closed): Ditto.
|
||||
(close_handle): Remove unneeded #if.
|
||||
* dtable.cc (dtable::dup2): Tweak debug output.
|
||||
|
||||
2009-08-04 Christopher Faylor <me+cygwin@cgf.cx>
|
||||
|
||||
* path.cc (patch_conv::check): Zero path before setting it.
|
||||
|
|
|
@ -230,7 +230,6 @@ public:
|
|||
struct cygheap_debug
|
||||
{
|
||||
handle_list starth;
|
||||
handle_list *endh;
|
||||
handle_list freeh[500];
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -27,20 +27,14 @@ details. */
|
|||
class lock_debug
|
||||
{
|
||||
static muto locker;
|
||||
bool acquired;
|
||||
public:
|
||||
lock_debug () : acquired (0)
|
||||
lock_debug ()
|
||||
{
|
||||
if (locker.name && !exit_state)
|
||||
acquired = !!locker.acquire (INFINITE);
|
||||
locker.acquire (INFINITE);
|
||||
}
|
||||
void unlock ()
|
||||
{
|
||||
if (locker.name && acquired)
|
||||
{
|
||||
locker.release ();
|
||||
acquired = false;
|
||||
}
|
||||
locker.release ();
|
||||
}
|
||||
~lock_debug () {unlock ();}
|
||||
friend void debug_init ();
|
||||
|
@ -64,7 +58,6 @@ find_handle (HANDLE h)
|
|||
for (hl = &cygheap->debug.starth; hl->next != NULL; hl = hl->next)
|
||||
if (hl->next->h == h)
|
||||
goto out;
|
||||
cygheap->debug.endh = hl;
|
||||
hl = NULL;
|
||||
|
||||
out:
|
||||
|
@ -74,6 +67,7 @@ out:
|
|||
void
|
||||
verify_handle (const char *func, int ln, HANDLE h)
|
||||
{
|
||||
lock_debug here;
|
||||
handle_list *hl = find_handle (h);
|
||||
if (!hl)
|
||||
return;
|
||||
|
@ -86,6 +80,7 @@ verify_handle (const char *func, int ln, HANDLE h)
|
|||
void
|
||||
setclexec (HANDLE oh, HANDLE nh, bool not_inheriting)
|
||||
{
|
||||
lock_debug here;
|
||||
handle_list *hl = find_handle (oh);
|
||||
if (hl)
|
||||
{
|
||||
|
@ -100,7 +95,6 @@ static handle_list * __stdcall
|
|||
newh ()
|
||||
{
|
||||
handle_list *hl;
|
||||
lock_debug here;
|
||||
|
||||
for (hl = cygheap->debug.freeh; hl < cygheap->debug.freeh + NFREEH; hl++)
|
||||
if (hl->name == NULL)
|
||||
|
@ -112,6 +106,7 @@ newh ()
|
|||
void __stdcall
|
||||
modify_handle (const char *func, int ln, HANDLE h, const char *name, bool inh)
|
||||
{
|
||||
lock_debug here;
|
||||
handle_list *hl = find_handle (h);
|
||||
if (!hl)
|
||||
{
|
||||
|
@ -128,11 +123,11 @@ void __stdcall
|
|||
add_handle (const char *func, int ln, HANDLE h, const char *name, bool inh)
|
||||
{
|
||||
handle_list *hl;
|
||||
lock_debug here;
|
||||
|
||||
if (!cygheap)
|
||||
return;
|
||||
|
||||
lock_debug here;
|
||||
if ((hl = find_handle (h)))
|
||||
{
|
||||
hl = hl->next;
|
||||
|
@ -156,11 +151,10 @@ add_handle (const char *func, int ln, HANDLE h, const char *name, bool inh)
|
|||
hl->name = name;
|
||||
hl->func = func;
|
||||
hl->ln = ln;
|
||||
hl->next = NULL;
|
||||
hl->inherited = inh;
|
||||
hl->pid = GetCurrentProcessId ();
|
||||
cygheap->debug.endh->next = hl;
|
||||
cygheap->debug.endh = hl;
|
||||
hl->next = cygheap->debug.starth.next;
|
||||
cygheap->debug.starth.next = hl;
|
||||
SetHandleInformation (h, HANDLE_FLAG_PROTECT_FROM_CLOSE, HANDLE_FLAG_PROTECT_FROM_CLOSE);
|
||||
debug_printf ("protecting handle '%s'(%p), inherited flag %d", hl->name, hl->h, hl->inherited);
|
||||
}
|
||||
|
@ -170,7 +164,7 @@ delete_handle (handle_list *hl)
|
|||
{
|
||||
handle_list *hnuke = hl->next;
|
||||
debug_printf ("nuking handle '%s' (%p)", hnuke->name, hnuke->h);
|
||||
hl->next = hl->next->next;
|
||||
hl->next = hnuke->next;
|
||||
memset (hnuke, 0, sizeof (*hnuke));
|
||||
}
|
||||
|
||||
|
@ -190,7 +184,6 @@ static bool __stdcall
|
|||
mark_closed (const char *func, int ln, HANDLE h, const char *name, bool force)
|
||||
{
|
||||
handle_list *hl;
|
||||
lock_debug here;
|
||||
|
||||
if (!cygheap)
|
||||
return true;
|
||||
|
@ -198,7 +191,6 @@ mark_closed (const char *func, int ln, HANDLE h, const char *name, bool force)
|
|||
if ((hl = find_handle (h)) && !force)
|
||||
{
|
||||
hl = hl->next;
|
||||
here.unlock (); // race here
|
||||
system_printf ("attempt to close protected handle %s:%d(%s<%p>) winpid %d",
|
||||
hl->func, hl->ln, hl->name, hl->h, hl->pid);
|
||||
system_printf (" by %s:%d(%s<%p>)", func, ln, name, h);
|
||||
|
@ -206,7 +198,7 @@ mark_closed (const char *func, int ln, HANDLE h, const char *name, bool force)
|
|||
}
|
||||
|
||||
handle_list *hln;
|
||||
if (hl && (hln = hl->next) && strcmp (name, hln->name))
|
||||
if (hl && (hln = hl->next) && strcmp (name, hln->name) != 0)
|
||||
{
|
||||
system_printf ("closing protected handle %s:%d(%s<%p>)",
|
||||
hln->func, hln->ln, hln->name, hln->h);
|
||||
|
@ -225,18 +217,16 @@ bool __stdcall
|
|||
close_handle (const char *func, int ln, HANDLE h, const char *name, bool force)
|
||||
{
|
||||
bool ret;
|
||||
lock_debug here;
|
||||
|
||||
lock_debug here;
|
||||
if (!mark_closed (func, ln, h, name, force))
|
||||
return false;
|
||||
|
||||
SetHandleInformation (h, HANDLE_FLAG_PROTECT_FROM_CLOSE, 0);
|
||||
ret = CloseHandle (h);
|
||||
|
||||
#if 1 /* Uncomment to see CloseHandle failures */
|
||||
if (!ret)
|
||||
small_printf ("CloseHandle(%s<%p>) failed %s:%d, %E\n", name, h, func, ln);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
#endif /*DEBUGGING*/
|
||||
|
|
|
@ -631,8 +631,8 @@ dtable::dup2 (int oldfd, int newfd)
|
|||
goto done;
|
||||
}
|
||||
|
||||
debug_printf ("newfh->io_handle %p, oldfh->io_handle %p",
|
||||
newfh->get_io_handle (), fds[oldfd]->get_io_handle ());
|
||||
debug_printf ("newfh->io_handle %p, oldfh->io_handle %p, new win32_name %p, old win32_name %p",
|
||||
newfh->get_io_handle (), fds[oldfd]->get_io_handle (), newfh->get_win32_name (), fds[oldfd]->get_win32_name ());
|
||||
|
||||
if (!not_open (newfd))
|
||||
close (newfd);
|
||||
|
|
Loading…
Reference in New Issue