aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-11-02 15:43:22 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2012-11-02 13:07:54 -0500
commitc8122c35e611385b31e2d8ccb059d0687540244a (patch)
treee6411bce103fe07ccae80e7060ba93c3c6db73f5
parentc166cb72f1676855816340666c3b618beef4b976 (diff)
qemu-timer: reinitialize timers after fork
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> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r--qemu-timer.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/qemu-timer.c b/qemu-timer.c
index f3426c9937..7b2217aab0 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;