Change requested in launchpad bug #1288352
[packages/centos6/qemu.git] / 0124-socket-don-t-attempt-to-reconnect-a-TCP-socket-in-se.patch
1 From 40874e295225675fec7b42bb8e015fb3f2065a69 Mon Sep 17 00:00:00 2001
2 From: Anthony Liguori <aliguori@us.ibm.com>
3 Date: Wed, 5 Sep 2012 13:52:49 -0500
4 Subject: [PATCH] socket: don't attempt to reconnect a TCP socket in server
5  mode
6
7 Commit c3767ed0eb5d0bb25fe409ae5dec06e3411ff1b6 introduced a possible SEGV when
8 using a socket chardev with server=on because it assumes that all TCP sockets
9 are in client mode.
10
11 This patch adds a check to only reconnect when in client mode.
12
13 Cc: Lei Li <lilei@linux.vnet.ibm.com>
14 Reported-by: Michael Roth <mdroth@linux.vnet.ibm.com>
15 Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
16 (cherry picked from commit 455aa1e0818653c41fd794435b982426ce21ba2f)
17
18 Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
19 ---
20  qemu-char.c | 4 +++-
21  1 file changed, 3 insertions(+), 1 deletion(-)
22
23 diff --git a/qemu-char.c b/qemu-char.c
24 index 398baf1..767da93 100644
25 --- a/qemu-char.c
26 +++ b/qemu-char.c
27 @@ -2148,10 +2148,12 @@ static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
28      TCPCharDriver *s = chr->opaque;
29      if (s->connected) {
30          return send_all(s->fd, buf, len);
31 -    } else {
32 +    } else if (s->listen_fd == -1) {
33          /* (Re-)connect for unconnected writing */
34          tcp_chr_connect(chr);
35          return 0;
36 +    } else {
37 +        return len;
38      }
39  }
40  
41 -- 
42 1.7.12.1
43