* 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:
		| @@ -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> | 2009-08-04  Christopher Faylor  <me+cygwin@cgf.cx> | ||||||
|  |  | ||||||
| 	* path.cc (patch_conv::check): Zero path before setting it. | 	* path.cc (patch_conv::check): Zero path before setting it. | ||||||
|   | |||||||
| @@ -230,7 +230,6 @@ public: | |||||||
| struct cygheap_debug | struct cygheap_debug | ||||||
| { | { | ||||||
|   handle_list starth; |   handle_list starth; | ||||||
|   handle_list *endh; |  | ||||||
|   handle_list freeh[500]; |   handle_list freeh[500]; | ||||||
| }; | }; | ||||||
| #endif | #endif | ||||||
|   | |||||||
| @@ -27,20 +27,14 @@ details. */ | |||||||
| class lock_debug | class lock_debug | ||||||
| { | { | ||||||
|   static muto locker; |   static muto locker; | ||||||
|   bool acquired; |  | ||||||
|  public: |  public: | ||||||
|   lock_debug () : acquired (0) |   lock_debug () | ||||||
|   { |   { | ||||||
|     if (locker.name && !exit_state) |     locker.acquire (INFINITE); | ||||||
|       acquired = !!locker.acquire (INFINITE); |  | ||||||
|   } |   } | ||||||
|   void unlock () |   void unlock () | ||||||
|   { |   { | ||||||
|     if (locker.name && acquired) |     locker.release (); | ||||||
|       { |  | ||||||
| 	locker.release (); |  | ||||||
| 	acquired = false; |  | ||||||
|       } |  | ||||||
|   } |   } | ||||||
|   ~lock_debug () {unlock ();} |   ~lock_debug () {unlock ();} | ||||||
|   friend void debug_init (); |   friend void debug_init (); | ||||||
| @@ -64,7 +58,6 @@ find_handle (HANDLE h) | |||||||
|   for (hl = &cygheap->debug.starth; hl->next != NULL; hl = hl->next) |   for (hl = &cygheap->debug.starth; hl->next != NULL; hl = hl->next) | ||||||
|     if (hl->next->h == h) |     if (hl->next->h == h) | ||||||
|       goto out; |       goto out; | ||||||
|   cygheap->debug.endh = hl; |  | ||||||
|   hl = NULL; |   hl = NULL; | ||||||
|  |  | ||||||
| out: | out: | ||||||
| @@ -74,6 +67,7 @@ out: | |||||||
| void | void | ||||||
| verify_handle (const char *func, int ln, HANDLE h) | verify_handle (const char *func, int ln, HANDLE h) | ||||||
| { | { | ||||||
|  |   lock_debug here; | ||||||
|   handle_list *hl = find_handle (h); |   handle_list *hl = find_handle (h); | ||||||
|   if (!hl) |   if (!hl) | ||||||
|     return; |     return; | ||||||
| @@ -86,6 +80,7 @@ verify_handle (const char *func, int ln, HANDLE h) | |||||||
| void | void | ||||||
| setclexec (HANDLE oh, HANDLE nh, bool not_inheriting) | setclexec (HANDLE oh, HANDLE nh, bool not_inheriting) | ||||||
| { | { | ||||||
|  |   lock_debug here; | ||||||
|   handle_list *hl = find_handle (oh); |   handle_list *hl = find_handle (oh); | ||||||
|   if (hl) |   if (hl) | ||||||
|     { |     { | ||||||
| @@ -100,7 +95,6 @@ static handle_list * __stdcall | |||||||
| newh () | newh () | ||||||
| { | { | ||||||
|   handle_list *hl; |   handle_list *hl; | ||||||
|   lock_debug here; |  | ||||||
|  |  | ||||||
|   for (hl = cygheap->debug.freeh; hl < cygheap->debug.freeh + NFREEH; hl++) |   for (hl = cygheap->debug.freeh; hl < cygheap->debug.freeh + NFREEH; hl++) | ||||||
|     if (hl->name == NULL) |     if (hl->name == NULL) | ||||||
| @@ -112,6 +106,7 @@ newh () | |||||||
| void __stdcall | void __stdcall | ||||||
| modify_handle (const char *func, int ln, HANDLE h, const char *name, bool inh) | modify_handle (const char *func, int ln, HANDLE h, const char *name, bool inh) | ||||||
| { | { | ||||||
|  |   lock_debug here; | ||||||
|   handle_list *hl = find_handle (h); |   handle_list *hl = find_handle (h); | ||||||
|   if (!hl) |   if (!hl) | ||||||
|     { |     { | ||||||
| @@ -128,11 +123,11 @@ void __stdcall | |||||||
| add_handle (const char *func, int ln, HANDLE h, const char *name, bool inh) | add_handle (const char *func, int ln, HANDLE h, const char *name, bool inh) | ||||||
| { | { | ||||||
|   handle_list *hl; |   handle_list *hl; | ||||||
|   lock_debug here; |  | ||||||
|  |  | ||||||
|   if (!cygheap) |   if (!cygheap) | ||||||
|     return; |     return; | ||||||
|  |  | ||||||
|  |   lock_debug here; | ||||||
|   if ((hl = find_handle (h))) |   if ((hl = find_handle (h))) | ||||||
|     { |     { | ||||||
|       hl = hl->next; |       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->name = name; | ||||||
|   hl->func = func; |   hl->func = func; | ||||||
|   hl->ln = ln; |   hl->ln = ln; | ||||||
|   hl->next = NULL; |  | ||||||
|   hl->inherited = inh; |   hl->inherited = inh; | ||||||
|   hl->pid = GetCurrentProcessId (); |   hl->pid = GetCurrentProcessId (); | ||||||
|   cygheap->debug.endh->next = hl; |   hl->next = cygheap->debug.starth.next; | ||||||
|   cygheap->debug.endh = hl; |   cygheap->debug.starth.next = hl; | ||||||
|   SetHandleInformation (h, HANDLE_FLAG_PROTECT_FROM_CLOSE, HANDLE_FLAG_PROTECT_FROM_CLOSE); |   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); |   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; |   handle_list *hnuke = hl->next; | ||||||
|   debug_printf ("nuking handle '%s' (%p)", hnuke->name, hnuke->h); |   debug_printf ("nuking handle '%s' (%p)", hnuke->name, hnuke->h); | ||||||
|   hl->next = hl->next->next; |   hl->next = hnuke->next; | ||||||
|   memset (hnuke, 0, sizeof (*hnuke)); |   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) | mark_closed (const char *func, int ln, HANDLE h, const char *name, bool force) | ||||||
| { | { | ||||||
|   handle_list *hl; |   handle_list *hl; | ||||||
|   lock_debug here; |  | ||||||
|  |  | ||||||
|   if (!cygheap) |   if (!cygheap) | ||||||
|     return true; |     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) |   if ((hl = find_handle (h)) && !force) | ||||||
|     { |     { | ||||||
|       hl = hl->next; |       hl = hl->next; | ||||||
|       here.unlock ();	// race here |  | ||||||
|       system_printf ("attempt to close protected handle %s:%d(%s<%p>) winpid %d", |       system_printf ("attempt to close protected handle %s:%d(%s<%p>) winpid %d", | ||||||
| 		     hl->func, hl->ln, hl->name, hl->h, hl->pid); | 		     hl->func, hl->ln, hl->name, hl->h, hl->pid); | ||||||
|       system_printf (" by %s:%d(%s<%p>)", func, ln, name, h); |       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; |   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>)", |       system_printf ("closing protected handle %s:%d(%s<%p>)", | ||||||
| 		     hln->func, hln->ln, hln->name, hln->h); | 		     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) | close_handle (const char *func, int ln, HANDLE h, const char *name, bool force) | ||||||
| { | { | ||||||
|   bool ret; |   bool ret; | ||||||
|   lock_debug here; |  | ||||||
|  |  | ||||||
|  |   lock_debug here; | ||||||
|   if (!mark_closed (func, ln, h, name, force)) |   if (!mark_closed (func, ln, h, name, force)) | ||||||
|     return false; |     return false; | ||||||
|  |  | ||||||
|   SetHandleInformation (h, HANDLE_FLAG_PROTECT_FROM_CLOSE, 0); |   SetHandleInformation (h, HANDLE_FLAG_PROTECT_FROM_CLOSE, 0); | ||||||
|   ret = CloseHandle (h); |   ret = CloseHandle (h); | ||||||
|  |  | ||||||
| #if 1 /* Uncomment to see CloseHandle failures */ |  | ||||||
|   if (!ret) |   if (!ret) | ||||||
|     small_printf ("CloseHandle(%s<%p>) failed %s:%d, %E\n", name, h, func, ln); |     small_printf ("CloseHandle(%s<%p>) failed %s:%d, %E\n", name, h, func, ln); | ||||||
| #endif |  | ||||||
|   return ret; |   return ret; | ||||||
| } | } | ||||||
| #endif /*DEBUGGING*/ | #endif /*DEBUGGING*/ | ||||||
|   | |||||||
| @@ -631,8 +631,8 @@ dtable::dup2 (int oldfd, int newfd) | |||||||
|       goto done; |       goto done; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   debug_printf ("newfh->io_handle %p, oldfh->io_handle %p", |   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_io_handle (), fds[oldfd]->get_io_handle (), newfh->get_win32_name (), fds[oldfd]->get_win32_name ()); | ||||||
|  |  | ||||||
|   if (!not_open (newfd)) |   if (!not_open (newfd)) | ||||||
|     close (newfd); |     close (newfd); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user