[ros-diffs] [cwittich] 24653: fix some issues when reading from a named pipe fix a typo terminate qemu at exit (when using named pipes)

cwittich at svn.reactos.org cwittich at svn.reactos.org
Wed Oct 25 22:02:01 CEST 2006


Author: cwittich
Date: Thu Oct 26 00:02:01 2006
New Revision: 24653

URL: http://svn.reactos.org/svn/reactos?rev=24653&view=rev
Log:
fix some issues when reading from a named pipe
fix a typo
terminate qemu at exit (when using named pipes)

Modified:
    trunk/reactos/tools/sysreg/namedpipe_reader.cpp
    trunk/reactos/tools/sysreg/rosboot_test.cpp

Modified: trunk/reactos/tools/sysreg/namedpipe_reader.cpp
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/namedpipe_reader.cpp?rev=24653&r1=24652&r2=24653&view=diff
==============================================================================
--- trunk/reactos/tools/sysreg/namedpipe_reader.cpp (original)
+++ trunk/reactos/tools/sysreg/namedpipe_reader.cpp Thu Oct 26 00:02:01 2006
@@ -97,6 +97,8 @@
 		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 @@
 #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);
 	}
 

Modified: trunk/reactos/tools/sysreg/rosboot_test.cpp
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/rosboot_test.cpp?rev=24653&r1=24652&r2=24653&view=diff
==============================================================================
--- trunk/reactos/tools/sysreg/rosboot_test.cpp (original)
+++ trunk/reactos/tools/sysreg/rosboot_test.cpp Thu Oct 26 00:02:01 2006
@@ -320,10 +320,11 @@
 		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));
@@ -338,6 +339,10 @@
 		{
 			cerr << "Error: CreateProcess failed " << boot_cmd <<endl;
 			return false;
+		}
+		else
+		{
+			pid = piProcInfo.dwProcessId;
 		}
 #endif
 
@@ -356,7 +361,7 @@
 		if (m_Delayread)
 		{
 			///
-			/// delay reading untill emulator is ready
+			/// delay reading until emulator is ready
 			///
 
 			_sleep( (clock_t)m_Delayread * CLOCKS_PER_SEC );
@@ -380,23 +385,35 @@
 				break;
 			}
 
-			namedpipe_reader.readPipe (Buffer);
-			cout << Buffer.c_str() << endl;
-			vect.push_back (Buffer);
-
-			DebugState state = checkDebugData(vect);
-
-			if (state == DebugStateBSODDetected || state == DebugStateUMEDetected)
-			{
-				ret = false;
-				break;
-			}
-			else if (state == DebugStateCPReached)
-			{
-				break;
+			if (namedpipe_reader.readPipe (Buffer) != 0)
+			{
+				vect.push_back (Buffer.c_str());
+
+				DebugState state = checkDebugData(vect);
+				if (state == DebugStateBSODDetected || state == DebugStateUMEDetected)
+				{
+					ret = false;
+					break;
+				}
+				else if (state == DebugStateCPReached)
+				{
+					break;
+				}
 			}
 		}
 		namedpipe_reader.closePipe ();
+
+#ifdef __LINUX__
+		kill(pid, SIGTERM);
+#else
+		HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
+		if (hProcess)
+		{
+			TerminateProcess(hProcess, 0);
+		}
+		CloseHandle(hProcess);
+#endif
+
 		return ret;
 	}
 //---------------------------------------------------------------------------------------




More information about the Ros-diffs mailing list