[2/4] net: clean up network at qemu process termination

Message ID 1357641939-20030-3-git-send-email-stefanha@redhat.com
State New
Headers show

Commit Message

Stefan Hajnoczi Jan. 8, 2013, 10:45 a.m.
From: Amos Kong <akong@redhat.com>

We don't clean up network if fails to parse "-device" parameters without
calling net_cleanup(). I touch a problem, the tap device which is
created by qemu-ifup script could not be removed by qemu-ifdown script.
Some similar problems also exist in vl.c

In this patch, if network initialization successes, a cleanup function
will be registered to be called at qemu process termination.

Signed-off-by: Amos Kong <akong@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
 vl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)


diff --git a/vl.c b/vl.c
index f056c95..79e5122 100644
--- a/vl.c
+++ b/vl.c
@@ -3762,6 +3762,9 @@  int main(int argc, char **argv, char **envp)
+    /* clean up network at qemu process termination */
+    atexit(&net_cleanup);
     if (net_init_clients() < 0) {
@@ -4014,7 +4017,6 @@  int main(int argc, char **argv, char **envp)
-    net_cleanup();
     return 0;