From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kraxel@redhat.com
Subject: [Qemu-devel] [PATCH 1/3] qemu-char: use consistent idiom for removing sources
Date: Tue, 16 Apr 2013 13:10:40 +0200 [thread overview]
Message-ID: <1366110642-22095-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1366110642-22095-1-git-send-email-pbonzini@redhat.com>
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 <pbonzini@redhat.com>
---
qemu-char.c | 32 +++++++++++++++++++++++---------
1 file 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);
--
1.8.1.4
next prev parent reply other threads:[~2013-04-16 11:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-16 11:10 [Qemu-devel] [PATCH 0/3] another round of qemu-char fixes Paolo Bonzini
2013-04-16 11:10 ` Paolo Bonzini [this message]
2013-04-16 11:10 ` [Qemu-devel] [PATCH 2/3] qemu-char: simplify pty polling Paolo Bonzini
2013-04-16 11:10 ` [Qemu-devel] [PATCH 3/3] qemu-char: correct return value from chr_read functions Paolo Bonzini
2013-04-16 11:22 ` [Qemu-devel] [PATCH 0/3] another round of qemu-char fixes Gerd Hoffmann
2013-04-17 7:06 ` Gerd Hoffmann
2013-04-17 9:28 ` Paolo Bonzini
2013-04-17 10:17 ` Paolo Bonzini
2013-04-18 6:14 ` Gerd Hoffmann
2013-04-18 12:38 ` Paolo Bonzini
2013-04-18 12:54 ` Gerd Hoffmann
2013-04-18 13:11 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1366110642-22095-2-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).