From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60790) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zu4Qq-0000Fe-H4 for qemu-devel@nongnu.org; Wed, 04 Nov 2015 15:13:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zu4Ql-0003jZ-OI for qemu-devel@nongnu.org; Wed, 04 Nov 2015 15:13:20 -0500 Received: from e39.co.us.ibm.com ([32.97.110.160]:38620) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zu4Ql-0003jK-Hn for qemu-devel@nongnu.org; Wed, 04 Nov 2015 15:13:15 -0500 Received: from localhost by e39.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 4 Nov 2015 13:13:15 -0700 Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id ADA0238C804A for ; Wed, 4 Nov 2015 15:13:12 -0500 (EST) Received: from d01av05.pok.ibm.com (d01av05.pok.ibm.com [9.56.224.195]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id tA4KDCMx65273928 for ; Wed, 4 Nov 2015 20:13:12 GMT Received: from d01av05.pok.ibm.com (localhost [127.0.0.1]) by d01av05.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id tA4KBqDT007752 for ; Wed, 4 Nov 2015 15:11:54 -0500 From: Michael Roth Date: Wed, 4 Nov 2015 14:12:17 -0600 Message-Id: <1446667937-12085-4-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1446667937-12085-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1446667937-12085-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PULL 3/3] qga: set file descriptor in qmp_guest_file_open non-blocking on Win32 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , peter.maydell@linaro.org, Stefan Weil , Michael Roth , Olga Krishtal From: Olga Krishtal Set fd non-blocking to avoid common use cases (like reading from a named pipe) from hanging the agent. This was missed in the original code. The patch introduces qemu_set_handle_nonoblocking, the local analog of qemu_set_nonblock for HANDLES. The usage of handles in qemu_set_non/block is impossible, because for win32 there is a difference between file discriptors and file handles, and all file ops are made via Win32 api. Signed-off-by: Olga Krishtal Signed-off-by: Denis V. Lunev CC: Michael Roth CC: Stefan Weil Signed-off-by: Michael Roth --- qga/commands-win32.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 97f19d5..a5306e7 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -128,6 +128,28 @@ static GuestFileHandle *guest_file_handle_find(int64_t id, Error **errp) return NULL; } +static void handle_set_nonblocking(HANDLE fh) +{ + DWORD file_type, pipe_state; + file_type = GetFileType(fh); + if (file_type != FILE_TYPE_PIPE) { + return; + } + /* If file_type == FILE_TYPE_PIPE, according to MSDN + * the specified file is socket or named pipe */ + if (!GetNamedPipeHandleState(fh, &pipe_state, NULL, + NULL, NULL, NULL, 0)) { + return; + } + /* The fd is named pipe fd */ + if (pipe_state & PIPE_NOWAIT) { + return; + } + + pipe_state |= PIPE_NOWAIT; + SetNamedPipeHandleState(fh, &pipe_state, NULL, NULL); +} + int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, Error **errp) { @@ -158,6 +180,11 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, return -1; } + /* set fd non-blocking to avoid common use cases (like reading from a + * named pipe) from hanging the agent + */ + handle_set_nonblocking(fh); + fd = guest_file_handle_add(fh, errp); if (fd < 0) { CloseHandle(fh); -- 1.9.1