From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:60494) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiLMb-0000ki-E0 for qemu-devel@nongnu.org; Tue, 11 Dec 2012 03:39:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TiLMU-0001dy-31 for qemu-devel@nongnu.org; Tue, 11 Dec 2012 03:38:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:9371) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiLMT-0001dh-SA for qemu-devel@nongnu.org; Tue, 11 Dec 2012 03:38:46 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBB8cixB003889 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 11 Dec 2012 03:38:45 -0500 Date: Tue, 11 Dec 2012 09:38:43 +0100 From: Stefan Hajnoczi Message-ID: <20121211083843.GB23282@stefanha-thinkpad.muc.redhat.com> References: <20121211055704.GA5080@t430s.nay.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20121211055704.GA5080@t430s.nay.redhat.com> Subject: Re: [Qemu-devel] Network isn't clean when qemu exits List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Amos Kong Cc: Qemu Devel Mail List , mst@redhat.com On Tue, Dec 11, 2012 at 01:57:04PM +0800, Amos Kong wrote: > In vl.c:main(), tap device would be created when net_init_clients() is called. > "device" option is parsed after calling net_init_clients() by: > # "qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) > > Qemu will exit 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. > > I did a quick fix, the tap device should be removed. > > But there are many "exit(1)" after calling net_init_clients() in vl.c, > it's ugly to call net_cleanup() before each exit. Not sure if we have > other exit(1) in other sub-functions, which is also called after calling > net_init_clients(). > > Any comments? > > ===== > @@ -3882,8 +3889,11 @@ int main(int argc, char **argv, char **envp) > } > > /* init generic devices */ > - if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, > NULL, 1) != 0) > + if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, > + NULL, 1) != 0) { > + net_cleanup(); > exit(1); > + } How about qemu_add_exit_notifier() or atexit(3)? Several other places in QEMU use this to clean up. Then you can also remove net_cleanup() from the end of vl.c:main() since it gets called implicitly. Stefan