Patchwork [3/5] qemu-timer: reinitialize timers after fork

login
register
mail settings
Submitter Paolo Bonzini
Date Nov. 2, 2012, 1:14 p.m.
Message ID <1351862047-23172-4-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/196562/
State New
Headers show

Comments

Paolo Bonzini - Nov. 2, 2012, 1:14 p.m.
Timers are not inherited by the child of a fork(2), so just use
pthread_atfork to reinstate them after daemonize.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qemu-timer.c | 15 ++++++++++++++-
 1 file modificato, 14 inserzioni(+). 1 rimozione(-)

Patch

diff --git a/qemu-timer.c b/qemu-timer.c
index f3426c9..1d87694 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -742,6 +742,17 @@  static void quit_timers(void)
     t->stop(t);
 }
 
+static void reinit_timers(void)
+{
+    struct qemu_alarm_timer *t = alarm_timer;
+    t->stop(t);
+    if (t->start(t)) {
+        fprintf(stderr, "Internal timer error: aborting\n");
+        exit(1);
+    }
+    qemu_rearm_alarm_timer(t);
+}
+
 int init_timer_alarm(void)
 {
     struct qemu_alarm_timer *t = NULL;
@@ -765,6 +776,9 @@  int init_timer_alarm(void)
     }
 
     atexit(quit_timers);
+#ifdef CONFIG_POSIX
+    pthread_atfork(NULL, NULL, reinit_timers);
+#endif
     alarm_timer = t;
     return 0;