]> sourceware.org Git - newlib-cygwin.git/commitdiff
* debug.h (ModifyHandle): Define new macro.
authorChristopher Faylor <me@cgf.cx>
Thu, 25 May 2006 05:40:51 +0000 (05:40 +0000)
committerChristopher Faylor <me@cgf.cx>
Thu, 25 May 2006 05:40:51 +0000 (05:40 +0000)
(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.

winsup/cygwin/ChangeLog
winsup/cygwin/debug.cc
winsup/cygwin/debug.h
winsup/cygwin/fhandler.cc
winsup/cygwin/fhandler.h
winsup/cygwin/pipe.cc

index fd23727066becfc62fa51f52f76e6f1d794eb89e..5b1db339a5a5b0a95b4aae1943996b4e793d5926 100644 (file)
@@ -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.
index 4e22afd5d5f363672e4050767b620c218676de12..004ddec0f2a3b973148154f2ad7a0fc105344757 100644 (file)
@@ -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)
index 94d4c5a2ba7b883e22f6956920fe833afa879221..e09208cf0ce3276dacbab9443bdb65277948ceca 100644 (file)
@@ -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;
index 66dffdc64637668a16fe13faa0e115ab533365fb..bd91551d6517bc64dcfad6d9542a13752a5c7249 100644 (file)
@@ -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
index 7fb5411a1513d0d423e0d7d78e128b4b804c16f7..61b10caab32101a2f566e4e5597b1223b1779902 100644 (file)
@@ -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);
index b6bd0cf0c8da90722c7b9d70aed3b4e5b33ba9c5..183bd18de657f6a8d50a51418db62b14e42ebdb5 100644 (file)
@@ -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 ();
This page took 0.03975 seconds and 5 git commands to generate.