(modify_handle): Declare new function.
* debug.cc (modify_handle): Define new function.
* fhandler.h (fhandler_base::fork_fixup): Change return value from void to
bool.
* fhandler.cc (fhandler_base::fork_fixup): Return true if fork fixup has been
done.
* pipe.cc (fhandler_pipe::set_close_on_exec): Set inheritance of protected
handle via ModifyHandle if DEBUGGING.
(fhandler_pipe::fixup_after_fork): Protect guard handle if fork fixup has been
done.
+2006-05-25 Christopher Faylor <cgf@timesys.com>
+
+ * debug.h (ModifyHandle): Define new macro.
+ (modify_handle): Declare new function.
+ * debug.cc (modify_handle): Define new function.
+ * fhandler.h (fhandler_base::fork_fixup): Change return value from void
+ to bool.
+ * fhandler.cc (fhandler_base::fork_fixup): Return true if fork fixup has
+ been done.
+ * pipe.cc (fhandler_pipe::set_close_on_exec): Set inheritance of
+ protected handle via ModifyHandle if DEBUGGING.
+ (fhandler_pipe::fixup_after_fork): Protect guard handle if fork fixup
+ has been done.
+
2006-05-24 Christopher Faylor <cgf@timesys.com>
* cygtls.cc (_cygtls::call): Call call2 using _my_tls.
return NULL;
}
+void __stdcall
+modify_handle (const char *func, int ln, HANDLE h, const char *name, bool inh)
+{
+ handle_list *hl = find_handle (h);
+ if (!hl)
+ {
+ system_printf ("%s:%d handle %s<%p> not found", func, ln, name, h);
+ return;
+ }
+ hl->next->inherited = inh;
+ debug_printf ("%s:%d set handle %s<%p> inheritance flag to %d", func, ln,
+ name, h, inh);
+}
+
/* Add a handle to the linked list of known handles. */
void __stdcall
add_handle (const char *func, int ln, HANDLE h, const char *name, bool inh)
# define ForceCloseHandle CloseHandle
# define ForceCloseHandle1(h, n) CloseHandle (h)
# define ForceCloseHandle2(h, n) CloseHandle (h)
+# define ModifyHandle(h, n) do {} while (0)
# define ProtectHandle(h) do {} while (0)
# define ProtectHandle1(h,n) do {} while (0)
# define ProtectHandle2(h,n) do {} while (0)
close_handle (__PRETTY_FUNCTION__, __LINE__, (h), n, TRUE)
# endif
+# define ModifyHandle(h, n) modify_handle (__PRETTY_FUNCTION__, __LINE__, (h), #h, n)
+
# define ProtectHandle(h) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), #h)
# define ProtectHandle1(h, n) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), #n)
# define ProtectHandle2(h, n) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), n)
__attribute__ ((regparm (3)));
bool __stdcall close_handle (const char *, int, HANDLE, const char *, bool)
__attribute__ ((regparm (3)));
-void __stdcall cygbench (const char *s) __attribute__ ((regparm (1)));
extern "C" void console_printf (const char *fmt,...);
+void __stdcall cygbench (const char *s) __attribute__ ((regparm (1)));
+void __stdcall modify_handle (const char *, int, HANDLE, const char *, bool)
+ __attribute__ ((regparm (3)));
void setclexec (HANDLE, HANDLE, bool);
void debug_fixup_after_fork_exec ();
extern int pinger;
#endif
}
-void
+bool
fhandler_base::fork_fixup (HANDLE parent, HANDLE &h, const char *name)
{
HANDLE oh = h;
+ bool res = false;
if (/* !is_socket () && */ !close_on_exec ())
debug_printf ("handle %p already opened", h);
else if (!DuplicateHandle (parent, h, hMainProc, &h, 0, !close_on_exec (),
DUPLICATE_SAME_ACCESS))
system_printf ("%s - %E, handle %s<%p>", get_name (), name, h);
- else if (oh != h)
- VerifyHandle (h);
+ else
+ {
+ if (oh != h)
+ VerifyHandle (h);
+ res = true;
+ }
+ return res;
}
void
virtual void set_no_inheritance (HANDLE &h, int not_inheriting);
/* fixup fd possibly non-inherited handles after fork */
- void fork_fixup (HANDLE parent, HANDLE &h, const char *name);
+ bool fork_fixup (HANDLE parent, HANDLE &h, const char *name);
virtual bool need_fixup_before () const {return false;}
int open_9x (int flags, mode_t mode = 0);
{
fhandler_base::set_close_on_exec (val);
if (guard)
- set_no_inheritance (guard, val);
+ {
+ set_no_inheritance (guard, val);
+ ModifyHandle (guard, !val);
+ }
if (writepipe_exists)
set_no_inheritance (writepipe_exists, val);
}
fhandler_pipe::fixup_after_fork (HANDLE parent)
{
fhandler_base::fixup_after_fork (parent);
- if (guard)
- fork_fixup (parent, guard, "guard");
+ if (guard && fork_fixup (parent, guard, "guard"))
+ ProtectHandle (guard);
if (writepipe_exists)
fork_fixup (parent, writepipe_exists, "writepipe_exists");
fixup_in_child ();