From patchwork Fri Apr 19 15:32:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 238041 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D98922C0232 for ; Sat, 20 Apr 2013 01:33:54 +1000 (EST) Received: from localhost ([::1]:59319 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTDJx-0007D4-3j for incoming@patchwork.ozlabs.org; Fri, 19 Apr 2013 11:33:53 -0400 Received: from eggs.gnu.org ([208.118.235.92]:54611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTDIR-00058E-Li for qemu-devel@nongnu.org; Fri, 19 Apr 2013 11:32:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UTDIO-0002Wl-Sk for qemu-devel@nongnu.org; Fri, 19 Apr 2013 11:32:19 -0400 Received: from mail-ea0-x234.google.com ([2a00:1450:4013:c01::234]:52881) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTDIO-0002WU-Ma for qemu-devel@nongnu.org; Fri, 19 Apr 2013 11:32:16 -0400 Received: by mail-ea0-f180.google.com with SMTP id d10so1801325eaj.39 for ; Fri, 19 Apr 2013 08:32:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=hyLWqKDoH4gEt8xnPxwrISM9gjZJ12CcJW6uhOUFK1g=; b=ezox4hC32Wf5p6coYf3QLo9tfUXrfx2mgsO8QLNt+/Sexe0T5ldmiEfODJmS7loVlj oilL6gHeFJa/0WUX4AUilFD5iJGzIna73XU5RGI0VYe8tVAqrU4UthZjhWtXk3jqSO02 +4VZSFovZkobleBL0If4A/TunwMV1lXvdecM4uggbgDsDJZ9BDcg2VZdlKeA7q20payF RlZhy7y4A8fUz5bS87jofTI3jxCOK+d/FPcOcNomrNd4m3DNV/X/WPnhsZ6qrMC1gIGM i52RSt9MoHM2V1Bx3fPGVd0hD2coBPNbK/Wsr7ufCLz0m98J6rjj7SV2VDXIerCeF5Rt m0hQ== X-Received: by 10.14.182.72 with SMTP id n48mr43404744eem.3.1366385535941; Fri, 19 Apr 2013 08:32:15 -0700 (PDT) Received: from localhost.localdomain (93-34-176-20.ip50.fastwebnet.it. [93.34.176.20]) by mx.google.com with ESMTPS id cb50sm23792906eeb.14.2013.04.19.08.32.14 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 19 Apr 2013 08:32:14 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 19 Apr 2013 17:32:06 +0200 Message-Id: <1366385529-10329-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1366385529-10329-1-git-send-email-pbonzini@redhat.com> References: <1366385529-10329-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c01::234 Cc: amit.shah@redhat.com, aliguori@us.ibm.com, kraxel@redhat.com Subject: [Qemu-devel] [PATCH v2 1/4] qemu-char: use consistent idiom for removing sources X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Always check that the source is active, and zero the tag afterwards. The occurrence in pty_chr_state will trigger with the next patch, the others are just theoretical. Signed-off-by: Paolo Bonzini --- qemu-char.c | 32 +++++++++++++++++++++++--------- 1 files changed, 23 insertions(+), 9 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index 728ed9b..552a498 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -644,9 +644,11 @@ static gboolean io_watch_poll_dispatch(GSource *source, GSourceFunc callback, static void io_watch_poll_finalize(GSource *source) { IOWatchPoll *iwp = io_watch_poll_from_source(source); - g_source_destroy(iwp->src); - g_source_unref(iwp->src); - iwp->src = NULL; + if (iwp->src) { + g_source_destroy(iwp->src); + g_source_unref(iwp->src); + iwp->src = NULL; + } } static GSourceFuncs io_watch_poll_funcs = { @@ -816,6 +818,7 @@ static void fd_chr_update_read_handler(CharDriverState *chr) if (s->fd_in_tag) { g_source_remove(s->fd_in_tag); + s->fd_in_tag = 0; } if (s->fd_in) { @@ -1148,8 +1151,10 @@ static void pty_chr_state(CharDriverState *chr, int connected) PtyCharDriver *s = chr->opaque; if (!connected) { - g_source_remove(s->fd_tag); - s->fd_tag = 0; + if (s->fd_tag) { + g_source_remove(s->fd_tag); + s->fd_tag = 0; + } s->connected = 0; s->polling = 0; /* (re-)connect poll interval for idle guests: once per second. @@ -1171,12 +1176,14 @@ static void pty_chr_close(struct CharDriverState *chr) if (s->fd_tag) { g_source_remove(s->fd_tag); + s->fd_tag = 0; } fd = g_io_channel_unix_get_fd(s->fd); g_io_channel_unref(s->fd); close(fd); if (s->timer_tag) { g_source_remove(s->timer_tag); + s->timer_tag = 0; } g_free(s); qemu_chr_be_event(chr, CHR_EVENT_CLOSED); @@ -2277,6 +2284,7 @@ static void udp_chr_close(CharDriverState *chr) NetCharDriver *s = chr->opaque; if (s->tag) { g_source_remove(s->tag); + s->tag = 0; } if (s->chan) { g_io_channel_unref(s->chan); @@ -2508,8 +2516,10 @@ static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque) if (s->listen_chan) { s->listen_tag = g_io_add_watch(s->listen_chan, G_IO_IN, tcp_chr_accept, chr); } - g_source_remove(s->tag); - s->tag = 0; + if (s->tag) { + g_source_remove(s->tag); + s->tag = 0; + } g_io_channel_unref(s->chan); s->chan = NULL; closesocket(s->fd); @@ -2570,8 +2580,10 @@ static int tcp_chr_add_client(CharDriverState *chr, int fd) socket_set_nodelay(fd); s->fd = fd; s->chan = io_channel_from_socket(fd); - g_source_remove(s->listen_tag); - s->listen_tag = 0; + if (s->listen_tag) { + g_source_remove(s->listen_tag); + s->listen_tag = 0; + } tcp_chr_connect(chr); return 0; @@ -2621,6 +2633,7 @@ static void tcp_chr_close(CharDriverState *chr) if (s->fd >= 0) { if (s->tag) { g_source_remove(s->tag); + s->tag = 0; } if (s->chan) { g_io_channel_unref(s->chan); @@ -2630,6 +2643,7 @@ static void tcp_chr_close(CharDriverState *chr) if (s->listen_fd >= 0) { if (s->listen_tag) { g_source_remove(s->listen_tag); + s->listen_tag = 0; } if (s->listen_chan) { g_io_channel_unref(s->listen_chan);