From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lncqa-0007cu-KY for qemu-devel@nongnu.org; Sat, 28 Mar 2009 14:01:32 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LncqZ-0007bi-UI for qemu-devel@nongnu.org; Sat, 28 Mar 2009 14:01:32 -0400 Received: from [199.232.76.173] (port=48074 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LncqZ-0007bQ-AR for qemu-devel@nongnu.org; Sat, 28 Mar 2009 14:01:31 -0400 Received: from savannah.gnu.org ([199.232.41.3]:54851 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LncqY-0002Q7-R4 for qemu-devel@nongnu.org; Sat, 28 Mar 2009 14:01:30 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1LncqY-0002ET-6C for qemu-devel@nongnu.org; Sat, 28 Mar 2009 18:01:30 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1LncqX-0002Di-QA for qemu-devel@nongnu.org; Sat, 28 Mar 2009 18:01:30 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Sat, 28 Mar 2009 18:01:29 +0000 Subject: [Qemu-devel] [6912] char: Fix closing of various char devices (Jan Kiszka) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 6912 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6912 Author: aliguori Date: 2009-03-28 18:01:29 +0000 (Sat, 28 Mar 2009) Log Message: ----------- char: Fix closing of various char devices (Jan Kiszka) This patch fixes several issues around closing char devices. Affected were pty (timer was left behind, even running), udp (no close handling at all) and tcp (missing async IO handler cleanup). The bugs either caused segfaults or stalled the qemu process. So far, hot-unplugging USB serial adapters suffered from this. Signed-off-by: Jan Kiszka Signed-off-by: Anthony Liguori Modified Paths: -------------- branches/stable_0_10/qemu-char.c Modified: branches/stable_0_10/qemu-char.c =================================================================== --- branches/stable_0_10/qemu-char.c 2009-03-28 17:58:14 UTC (rev 6911) +++ branches/stable_0_10/qemu-char.c 2009-03-28 18:01:29 UTC (rev 6912) @@ -917,6 +917,8 @@ qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); close(s->fd); + qemu_del_timer(s->timer); + qemu_free_timer(s->timer); qemu_free(s); } @@ -1746,6 +1748,16 @@ } } +static void udp_chr_close(CharDriverState *chr) +{ + NetCharDriver *s = chr->opaque; + if (s->fd >= 0) { + qemu_set_fd_handler(s->fd, NULL, NULL, NULL); + closesocket(s->fd); + } + qemu_free(s); +} + static CharDriverState *qemu_chr_open_udp(const char *def) { CharDriverState *chr = NULL; @@ -1779,6 +1791,7 @@ chr->opaque = s; chr->chr_write = udp_chr_write; chr->chr_update_read_handler = udp_chr_update_read_handler; + chr->chr_close = udp_chr_close; return chr; return_err: @@ -1981,10 +1994,14 @@ static void tcp_chr_close(CharDriverState *chr) { TCPCharDriver *s = chr->opaque; - if (s->fd >= 0) + if (s->fd >= 0) { + qemu_set_fd_handler(s->fd, NULL, NULL, NULL); closesocket(s->fd); - if (s->listen_fd >= 0) + } + if (s->listen_fd >= 0) { + qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL); closesocket(s->listen_fd); + } qemu_free(s); }