From a94c4a796ecd54484529606a2267f8edc670ddb0 Mon Sep 17 00:00:00 2001 From: Christoph von Wittich Date: Wed, 25 Oct 2006 20:02:01 +0000 Subject: [PATCH] fix some issues when reading from a named pipe fix a typo terminate qemu at exit (when using named pipes) svn path=/trunk/; revision=24653 --- reactos/tools/sysreg/namedpipe_reader.cpp | 51 ++++++++++++++++------- reactos/tools/sysreg/rosboot_test.cpp | 47 ++++++++++++++------- 2 files changed, 67 insertions(+), 31 deletions(-) diff --git a/reactos/tools/sysreg/namedpipe_reader.cpp b/reactos/tools/sysreg/namedpipe_reader.cpp index efc9dfe1c89..309a2f85526 100644 --- a/reactos/tools/sysreg/namedpipe_reader.cpp +++ b/reactos/tools/sysreg/namedpipe_reader.cpp @@ -97,6 +97,8 @@ namespace System_ string::size_type size = Buffer.capacity(); DWORD cbRead; BOOL fSuccess; + TCHAR * localbuf; + DWORD localsize = 100; //#ifdef NDEBUG memset(buf, 0x0, sizeof(TCHAR) * size); @@ -105,25 +107,42 @@ namespace System_ #ifdef __LINUX__ #else - do - { - fSuccess = ReadFile( - h_Pipe, - buf, - size, - &cbRead, - NULL); - - if (! fSuccess && GetLastError() != ERROR_MORE_DATA) - break; - - _tprintf( TEXT("%s\n"), buf ); - } while (!fSuccess); // repeat loop if ERROR_MORE_DATA + localbuf = (TCHAR*) HeapAlloc(GetProcessHeap(), 0, localsize * sizeof(TCHAR)); + if (localbuf != NULL) + { - if (!fSuccess) + do + { + do + { + ZeroMemory(localbuf, sizeof(localsize) * sizeof(TCHAR)); + + fSuccess = ReadFile( + h_Pipe, + localbuf, + localsize * sizeof(TCHAR), + &cbRead, + NULL); + + if (! fSuccess && GetLastError() != ERROR_MORE_DATA) + break; + + _tcscat(buf, localbuf); + + } while (!fSuccess); // repeat loop if ERROR_MORE_DATA + } while (localbuf[_tcslen(localbuf)-1] != '\n'); + + if (!fSuccess) + return 0; + + HeapFree(GetProcessHeap(), 0, localbuf); + } + else + { return 0; + } #endif - + buf[_tcslen(buf)-_tcslen(_T("\n"))-1] = '\0'; return _tcslen(buf); } diff --git a/reactos/tools/sysreg/rosboot_test.cpp b/reactos/tools/sysreg/rosboot_test.cpp index 88c933687a2..e6d15031419 100644 --- a/reactos/tools/sysreg/rosboot_test.cpp +++ b/reactos/tools/sysreg/rosboot_test.cpp @@ -320,10 +320,11 @@ namespace Sysreg_ string pipecmd = _T(""); #ifdef __LINUX__ - + pid_t pid; #else STARTUPINFO siStartInfo; PROCESS_INFORMATION piProcInfo; + DWORD pid; ZeroMemory(&siStartInfo, sizeof(STARTUPINFO)); ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION)); @@ -339,6 +340,10 @@ namespace Sysreg_ cerr << "Error: CreateProcess failed " << boot_cmd <