Files
UnrealEngineUWP/Engine/Source/Programs/UnrealVirtualizationTool/Private/ProcessUtilities.h
paul chipchase d8024ee02b [UVT] Fix a bug where the child process was launched with an incorrect stdin pipe attached.
#rb Per.Larsson
#rnx

- The problem with the process set up is described properly in UE-208628, but the quick summary is that a lot of our code is creating a single pipe, then using the input as stdin and the output as stdout when launching a child process so if that process ever did read from stdin it would end up using it's own output. Then we are copy/pasting the same bug around the code base,
- Fixed the problem by adding a second pipe to FProcessPipes.

[CL 32465578 by paul chipchase in ue5-main branch]
2024-03-25 04:43:00 -04:00

78 lines
1.6 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "Containers/Array.h"
#include "Containers/UnrealString.h"
#include "HAL/PlatformProcess.h"
#include "Logging/LogMacros.h"
#include "UnrealVirtualizationTool.h"
namespace UE::Virtualization
{
/** Wrapper around stdin and stdout pipes created by a call to FPlatformProcess::CreatePipe */
struct FProcessPipes
{
FProcessPipes()
{
verify(FPlatformProcess::CreatePipe(StdOutReadPipe, StdOutWritePipe, false));
verify(FPlatformProcess::CreatePipe(StdInReadPipe, StdInWritePipe, true));
}
~FProcessPipes()
{
FPlatformProcess::ClosePipe(StdOutReadPipe, StdOutWritePipe);
FPlatformProcess::ClosePipe(StdInReadPipe, StdInWritePipe);
}
void ProcessStdOut()
{
check(GetStdOutForReading() != nullptr);
FString Output = FPlatformProcess::ReadPipe(GetStdOutForReading());
while (!Output.IsEmpty())
{
TArray<FString> Lines;
Output.ParseIntoArray(Lines, LINE_TERMINATOR);
for (const FString& Line : Lines)
{
UE_LOG(LogVirtualizationTool, Display, TEXT("Child Process-> %s"), *Line);
}
Output = FPlatformProcess::ReadPipe(GetStdOutForReading());
}
}
void* GetStdInForProcess() const
{
return StdInReadPipe;
}
void* GetStdInForWriting() const
{
return StdInWritePipe;
}
void* GetStdOutForProcess() const
{
return StdOutWritePipe;
}
void* GetStdOutForReading() const
{
return StdOutReadPipe;
}
private:
void* StdOutReadPipe = nullptr;
void* StdOutWritePipe = nullptr;
void* StdInReadPipe = nullptr;
void* StdInWritePipe = nullptr;
};
} // namespace UE::Virtualization