[newlib-cygwin] Cygwin: timerfd: implement execve semantics

Corinna Vinschen corinna@sourceware.org
Wed Jan 16 17:41:00 GMT 2019


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=0e8c7b8689d18b75371ee3411a3ac68ed37fa3ef

commit 0e8c7b8689d18b75371ee3411a3ac68ed37fa3ef
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Wed Jan 16 18:40:26 2019 +0100

    Cygwin: timerfd: implement execve semantics
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/fhandler_timerfd.cc |  9 +++++++--
 winsup/cygwin/timer.cc            | 28 +++++++++++++++++-----------
 winsup/cygwin/timer.h             |  6 ++++--
 3 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/winsup/cygwin/fhandler_timerfd.cc b/winsup/cygwin/fhandler_timerfd.cc
index 8ce91af..cbcbefd 100644
--- a/winsup/cygwin/fhandler_timerfd.cc
+++ b/winsup/cygwin/fhandler_timerfd.cc
@@ -161,10 +161,15 @@ fhandler_timerfd::dup (fhandler_base *child, int flags)
 void
 fhandler_timerfd::fixup_after_exec ()
 {
-  if (!close_on_exec ())
+  if (close_on_exec ())
+    return;
+  __try
     {
-      /* TODO after exec */
+      timer_tracker *tt = (timer_tracker *) timerid;
+      tt->fixup_after_exec ();
     }
+  __except (EFAULT) {}
+  __endtry
 }
 
 int
diff --git a/winsup/cygwin/timer.cc b/winsup/cygwin/timer.cc
index bd412f0..be3fcf7 100644
--- a/winsup/cygwin/timer.cc
+++ b/winsup/cygwin/timer.cc
@@ -108,16 +108,6 @@ timer_tracker::timer_tracker (clockid_t c, const sigevent *e, bool fd)
     }
 }
 
-void timer_tracker::increment_instances ()
-{
-  InterlockedIncrement (&instance_count);
-}
-
-LONG timer_tracker::decrement_instances ()
-{
-  return InterlockedDecrement (&instance_count);
-}
-
 static inline int64_t
 timespec_to_us (const timespec& ts)
 {
@@ -152,7 +142,6 @@ timer_tracker::_disarm_event ()
     yield ();
   if (ret == EVENT_ARMED)
     {
-
       InterlockedExchange64 (&overrun_count_curr, overrun_count);
       ret = overrun_count_curr;
       InterlockedExchange64 (&overrun_count, 0);
@@ -461,6 +450,23 @@ timer_tracker::restart ()
     }
 }
 
+/* Only called from fhandler_timerfd::fixup_after_exec.  Note that
+   we don't touch the instance count.  This is handled by closing
+   the timer from fhandler_timerfd::close on O_CLOEXEC.  Ultimately
+   the instance count should be correct after execve. */
+void
+timer_tracker::fixup_after_exec ()
+{
+  lock_timer_tracker here;
+  /* Check if timer is already in the list. If so, skip it. */
+  for (timer_tracker *tt = &ttstart; tt->next != NULL; tt = tt->next)
+    if (tt->next == this)
+      return;
+  next = ttstart.next;
+  ttstart.next = this;
+  restart ();
+}
+
 void
 timer_tracker::fixup_after_fork ()
 {
diff --git a/winsup/cygwin/timer.h b/winsup/cygwin/timer.h
index f4c89bc..3b426a3 100644
--- a/winsup/cygwin/timer.h
+++ b/winsup/cygwin/timer.h
@@ -30,7 +30,7 @@ class timer_tracker
   LONG64 overrun_count;
 
   bool cancel ();
-  LONG decrement_instances ();
+  LONG decrement_instances () { return InterlockedDecrement (&instance_count); }
   int clean_and_unhook ();
   LONG64 _disarm_event ();
   void restart ();
@@ -45,7 +45,8 @@ class timer_tracker
   ~timer_tracker ();
   inline bool is_timer_tracker () const { return magic == TT_MAGIC; }
 
-  void increment_instances ();
+
+  void increment_instances () { InterlockedIncrement (&instance_count); }
   LONG64 wait (bool nonblocking);
   HANDLE get_timerfd_handle () const { return timerfd_event; }
 
@@ -58,6 +59,7 @@ class timer_tracker
   unsigned int disarm_event ();
 
   DWORD thread_func ();
+  void fixup_after_exec ();
   static void fixup_after_fork ();
   static int close (timer_tracker *tt);
 };



More information about the Cygwin-cvs mailing list