Blame 0124-socket-don-t-attempt-to-reconnect-a-TCP-socket-in-se.patch

5544c1
From 40874e295225675fec7b42bb8e015fb3f2065a69 Mon Sep 17 00:00:00 2001
5544c1
From: Anthony Liguori <aliguori@us.ibm.com>
5544c1
Date: Wed, 5 Sep 2012 13:52:49 -0500
5544c1
Subject: [PATCH] socket: don't attempt to reconnect a TCP socket in server
5544c1
 mode
5544c1
5544c1
Commit c3767ed0eb5d0bb25fe409ae5dec06e3411ff1b6 introduced a possible SEGV when
5544c1
using a socket chardev with server=on because it assumes that all TCP sockets
5544c1
are in client mode.
5544c1
5544c1
This patch adds a check to only reconnect when in client mode.
5544c1
5544c1
Cc: Lei Li <lilei@linux.vnet.ibm.com>
5544c1
Reported-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
5544c1
(cherry picked from commit 455aa1e0818653c41fd794435b982426ce21ba2f)
5544c1
5544c1
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1
---
5544c1
 qemu-char.c | 4 +++-
5544c1
 1 file changed, 3 insertions(+), 1 deletion(-)
5544c1
5544c1
diff --git a/qemu-char.c b/qemu-char.c
5544c1
index 398baf1..767da93 100644
5544c1
--- a/qemu-char.c
5544c1
+++ b/qemu-char.c
5544c1
@@ -2148,10 +2148,12 @@ static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
5544c1
     TCPCharDriver *s = chr->opaque;
5544c1
     if (s->connected) {
5544c1
         return send_all(s->fd, buf, len);
5544c1
-    } else {
5544c1
+    } else if (s->listen_fd == -1) {
5544c1
         /* (Re-)connect for unconnected writing */
5544c1
         tcp_chr_connect(chr);
5544c1
         return 0;
5544c1
+    } else {
5544c1
+        return len;
5544c1
     }
5544c1
 }
5544c1
 
5544c1
-- 
5544c1
1.7.12.1
5544c1