From faec3c0dfdcc08cb3e02a51b75b3619afc9e5597 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 29 Dec 2010 08:40:09 +0000 Subject: [PATCH] Only await POLLOUT events until connected Non-blocking socket connect(2) involves waiting for the socket to become writeable to detect that a connection has been made. POLLIN events should not be requested until the socket is connected because they are processed even if the iSCSI context is not yet connected. For example, the QEMU iscsi block driver does something like this: iscsi_full_connect_async(...) /* Now wait until the socket becomes ready */ poll(POLLIN|POLLOUT) = POLLIN|POLLOUT /* QEMU calls POLLIN and POLLOUT handlers individually and it happens to * call the POLLIN handler *before* the POLLOUT handler. */ iscsi_service(POLLIN) iscsi_service(POLLOUT) POLLIN processing will read from the socket and consume the error code if connect failed. As a result, the POLLOUT handler will write to a disconnected socket and raise a SIGPIPE which kills the process. Signed-off-by: Stefan Hajnoczi --- lib/socket.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/socket.c b/lib/socket.c index e3b9a6c..1ad1dd9 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -165,11 +165,7 @@ iscsi_get_fd(struct iscsi_context *iscsi) int iscsi_which_events(struct iscsi_context *iscsi) { - int events = POLLIN; - - if (iscsi->is_connected == 0) { - events |= POLLOUT; - } + int events = iscsi->is_connected ? POLLIN : POLLOUT; if (iscsi->outqueue) { events |= POLLOUT;