From patchwork Sun Sep 20 15:16:28 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 48904 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n8KFJREk015071 for ; Sun, 20 Sep 2009 15:19:27 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753912AbZITPTW (ORCPT ); Sun, 20 Sep 2009 11:19:22 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753890AbZITPTV (ORCPT ); Sun, 20 Sep 2009 11:19:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29071 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753645AbZITPTU (ORCPT ); Sun, 20 Sep 2009 11:19:20 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8KFJNLb032233; Sun, 20 Sep 2009 11:19:23 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8KFJM2B004271; Sun, 20 Sep 2009 11:19:23 -0400 Received: from localhost.localdomain (dhcp-1-188.tlv.redhat.com [10.35.1.188]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n8KFJJCY001335; Sun, 20 Sep 2009 11:19:21 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 2/4] KVM test: rss.cpp: send characters to the console window rather than directly to STDIN Date: Sun, 20 Sep 2009 18:16:28 +0300 Message-Id: <1253459790-17859-2-git-send-email-mgoldish@redhat.com> In-Reply-To: <1253459790-17859-1-git-send-email-mgoldish@redhat.com> References: <1253459790-17859-1-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Some Windows programs behave badly when their STDIN is redirected to a pipe (most notably wmic). Therefore, keep STDIN unredirected, and send input to the console window as a series of WM_CHAR messages. Signed-off-by: Michael Goldish --- client/tests/kvm/deps/rss.cpp | 54 +++++++++++++++++----------------------- 1 files changed, 23 insertions(+), 31 deletions(-) diff --git a/client/tests/kvm/deps/rss.cpp b/client/tests/kvm/deps/rss.cpp index 73a849a..66d9a5b 100644 --- a/client/tests/kvm/deps/rss.cpp +++ b/client/tests/kvm/deps/rss.cpp @@ -22,9 +22,9 @@ struct client_info { SOCKET socket; sockaddr_in addr; int pid; + HWND hwnd; HANDLE hJob; HANDLE hChildOutputRead; - HANDLE hChildInputWrite; HANDLE hThreadChildToSocket; }; @@ -161,15 +161,10 @@ DWORD WINAPI SocketToChild(LPVOID client_info_ptr) sprintf(message, "Client (%s) entered text: \"%s\"\r\n", client_info_str, formatted_buffer); AppendMessage(message); - // Write the data to the child's STDIN - WriteFile(ci.hChildInputWrite, buffer, bytes_received, - &bytes_written, NULL); - // Make sure all the data was written - if (bytes_written != bytes_received) { - sprintf(message, - "SocketToChild: bytes received (%d) != bytes written (%d)", - bytes_received, bytes_written); - ExitOnError(message, 1); + // Send the data as a series of WM_CHAR messages to the console window + for (int i=0; ihJob = CreateJobObject(NULL, NULL); AssignProcessToJobObject(ci->hJob, pi.hProcess); + // Keep the console window's handle + ci->hwnd = GetConsoleWindow(); + + // Detach from the child's console + FreeConsole(); } void SpawnSession(client_info *ci) { HANDLE hOutputReadTmp, hOutputRead, hOutputWrite; - HANDLE hInputWriteTmp, hInputRead, hInputWrite; HANDLE hErrorWrite; SECURITY_ATTRIBUTES sa; @@ -261,10 +266,6 @@ void SpawnSession(client_info *ci) TRUE, DUPLICATE_SAME_ACCESS)) ExitOnError("DuplicateHandle failed"); - // Create the child input pipe. - if (!CreatePipe(&hInputRead, &hInputWriteTmp, &sa, 0)) - ExitOnError("CreatePipe failed"); - // Create new output read handle and the input write handles. Set // the Properties to FALSE. Otherwise, the child inherits the // properties and, as a result, non-closeable handles to the pipes @@ -276,29 +277,20 @@ void SpawnSession(client_info *ci) DUPLICATE_SAME_ACCESS)) ExitOnError("DuplicateHandle failed"); - if (!DuplicateHandle(GetCurrentProcess(), hInputWriteTmp, - GetCurrentProcess(), - &hInputWrite, // Address of new handle. - 0, FALSE, // Make it uninheritable. - DUPLICATE_SAME_ACCESS)) - ExitOnError("DuplicateHandle failed"); - // Close inheritable copies of the handles you do not want to be // inherited. - if (!CloseHandle(hOutputReadTmp)) ExitOnError("CloseHandle failed"); - if (!CloseHandle(hInputWriteTmp)) ExitOnError("CloseHandle failed"); + if (!CloseHandle(hOutputReadTmp)) + ExitOnError("CloseHandle failed"); - PrepAndLaunchRedirectedChild(ci, hOutputWrite, hInputRead, hErrorWrite); + PrepAndLaunchRedirectedChild(ci, hOutputWrite, hErrorWrite); ci->hChildOutputRead = hOutputRead; - ci->hChildInputWrite = hInputWrite; // Close pipe handles (do not continue to modify the parent). // You need to make sure that no handles to the write end of the // output pipe are maintained in this process or else the pipe will // not close when the child process exits and the ReadFile will hang. if (!CloseHandle(hOutputWrite)) ExitOnError("CloseHandle failed"); - if (!CloseHandle(hInputRead )) ExitOnError("CloseHandle failed"); if (!CloseHandle(hErrorWrite)) ExitOnError("CloseHandle failed"); }