Handle only new incoming data for listener and stop fds, treat all other
events as error events which close the socket.

This fixes the bug where a 'kvm list' could have hanged because a close
event in the listener fd have been treated as a new connection.

Cc: Osier Yang <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
---
 tools/kvm/kvm-ipc.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/kvm/kvm-ipc.c b/tools/kvm/kvm-ipc.c
index 3131fe8..40ab457 100644
--- a/tools/kvm/kvm-ipc.c
+++ b/tools/kvm/kvm-ipc.c
@@ -112,7 +112,7 @@ static void *kvm_ipc__thread(void *param)
                if (nfds > 0) {
                        int fd = event.data.fd;
 
-                       if (fd == stop_fd) {
+                       if (fd == stop_fd && event.events & EPOLLIN) {
                                break;
                        } else if (fd == server_fd) {
                                int client;
@@ -138,13 +138,13 @@ int kvm_ipc__start(int sock)
 
        epoll_fd = epoll_create(KVM_IPC_MAX_MSGS);
 
-       ev.events = EPOLLIN | EPOLLOUT | EPOLLPRI;
+       ev.events = EPOLLIN | EPOLLET;
        ev.data.fd = sock;
        if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev) < 0)
                die("Failed starting IPC thread");
 
        stop_fd = eventfd(0, 0);
-       ev.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET;
+       ev.events = EPOLLIN | EPOLLET;
        ev.data.fd = stop_fd;
        if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, stop_fd, &ev) < 0)
                die("Failed adding stop event to epoll");
-- 
1.7.7.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to