Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--winsup/cygwin/ChangeLog14
-rw-r--r--winsup/cygwin/debug.cc14
-rw-r--r--winsup/cygwin/debug.h7
-rw-r--r--winsup/cygwin/fhandler.cc12
-rw-r--r--winsup/cygwin/fhandler.h2
-rw-r--r--winsup/cygwin/pipe.cc9
6 files changed, 50 insertions, 8 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index fd2372706..5b1db339a 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,17 @@
+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.
diff --git a/winsup/cygwin/debug.cc b/winsup/cygwin/debug.cc
index 4e22afd5d..004ddec0f 100644
--- a/winsup/cygwin/debug.cc
+++ b/winsup/cygwin/debug.cc
@@ -114,6 +114,20 @@ newh ()
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)
diff --git a/winsup/cygwin/debug.h b/winsup/cygwin/debug.h
index 94d4c5a2b..e09208cf0 100644
--- a/winsup/cygwin/debug.h
+++ b/winsup/cygwin/debug.h
@@ -28,6 +28,7 @@ details. */
# 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)
@@ -55,6 +56,8 @@ details. */
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)
@@ -70,8 +73,10 @@ void __stdcall verify_handle (const char *, int, HANDLE)
__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;
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index 66dffdc64..bd91551d6 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -1464,17 +1464,23 @@ fhandler_base::set_no_inheritance (HANDLE &h, int not_inheriting)
#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
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 7fb5411a1..61b10caab 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -252,7 +252,7 @@ class fhandler_base
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);
diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc
index b6bd0cf0c..183bd18de 100644
--- a/winsup/cygwin/pipe.cc
+++ b/winsup/cygwin/pipe.cc
@@ -155,7 +155,10 @@ fhandler_pipe::set_close_on_exec (bool val)
{
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);
}
@@ -250,8 +253,8 @@ void
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 ();