Index: debug.cc =================================================================== RCS file: /cvs/uberbaum/winsup/cygwin/debug.cc,v retrieving revision 1.25 diff -u -p -2 -r1.25 debug.cc --- debug.cc 2001/10/16 03:31:50 1.25 +++ debug.cc 2001/10/22 20:16:42 @@ -291,4 +291,16 @@ delete_handle (handle_list *hl) } +void __stdcall +update_handle (const char *func, int ln, HANDLE oldh, HANDLE newh) +{ + handle_list *hl; + lock_debug (); + + if ((hl = find_handle (oldh))) + hl->next->h = newh; + + unlock_debug (); +} + void debug_fixup_after_fork () Index: debug.h =================================================================== RCS file: /cvs/uberbaum/winsup/cygwin/debug.h,v retrieving revision 1.13 diff -u -p -2 -r1.13 debug.h --- debug.h 2001/10/05 04:37:33 1.13 +++ debug.h 2001/10/22 20:16:42 @@ -43,4 +43,5 @@ int __stdcall iscygthread (); # define ProtectHandle1(h,n) do {} while (0) # define ProtectHandle2(h,n) do {} while (0) +# define ReregisterHandle(oldh,newh) do {} while (0) # define debug_init() do {} while (0) # define setclexec_pid(h, b) do {} while (0) @@ -65,4 +66,5 @@ int __stdcall iscygthread (); # define ProtectHandle1(h, n) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), #n) # define ProtectHandle2(h, n) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), n) +# define ReregisterHandle(oldh,newh) update_handle (__PRETTY_FUNCTION__, __LINE__, (oldh), (newh)) void debug_init (); @@ -70,4 +72,6 @@ void __stdcall add_handle (const char *, __attribute__ ((regparm (3))); BOOL __stdcall close_handle (const char *, int, HANDLE, const char *, BOOL) + __attribute__ ((regparm (3))); +void __stdcall update_handle (const char *, int, HANDLE, HANDLE) __attribute__ ((regparm (3))); void __stdcall cygbench (const char *s) __attribute__ ((regparm (1))); Index: fhandler.cc =================================================================== RCS file: /cvs/uberbaum/winsup/cygwin/fhandler.cc,v retrieving revision 1.96 diff -u -p -2 -r1.96 fhandler.cc --- fhandler.cc 2001/10/16 16:58:28 1.96 +++ fhandler.cc 2001/10/22 20:16:42 @@ -1619,8 +1619,11 @@ fhandler_base::set_inheritance (HANDLE & what we want. If this changes in the future, we may be forced to use SetHandleInformation on newer OS's */ - if (!DuplicateHandle (hMainProc, h, hMainProc, &h, 0, !not_inheriting, + HANDLE newh; + if (!DuplicateHandle (hMainProc, h, hMainProc, &newh, 0, !not_inheriting, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)) debug_printf ("DuplicateHandle failed, %E"); #ifdef DEBUGGING + ReregisterHandle (h, newh); + h = newh; setclexec_pid (h, not_inheriting); #endif