/*** Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: AuProcess.Unix.hpp File: Process.Linux.hpp Date: 2021-6-12 Author: Reece ***/ #pragma once #include #include #if defined(AURORA_IS_LINUX_DERIVED) #include #include using ProcessPipeFileStream = Aurora::IO::FS::LinuxAsyncFileStream; #else #include using ProcessPipeFileStream = Aurora::IO::FS::UnixAsyncFileStream; #endif namespace Aurora::Processes { void DeinitUnix(); void InitUnix(); struct ProcessImpl : IProcess { ProcessImpl(StartupParameters &¶ms); ~ProcessImpl(); void ShutdownPipes(); bool HasExited() override; bool TryKill() override; bool Terminate() override; AuSPtr AsWaitable() override; AuSPtr AsLoopSource() override; AuSInt GetExitCode() override; AuUInt GetProcessId() override; bool Read(EStandardHandle stream, const AuMemoryViewStreamWrite &destination, bool nonblock) override; bool Write(const AuMemoryViewStreamRead &source) override; AuSPtr NewAsyncTransaction() override; AuSPtr NewErrorStreamAsyncTransaction() override; AuSPtr GetOutputAndInputHandles() override; AuSPtr GetErrorStreamHandle() override; AuSPtr ToStreamReader(EStandardHandle stream) override; AuSPtr ToStreamWriter() override; bool Start() override; bool Init(); void ByeLol(AuSInt code); void ForkMain(); void HookMainDeath(); private: int pipeStdOut_[2] { -1, -1 }; int pipeStdErr_[2] { -1, -1 }; int pipeStdIn_ [2] { -1, -1 }; bool bDontRelOut_ {}; bool bDontRelIn_ {}; bool bDontRelErr_ {}; AuSPtr loopSource_; AuSPtr fsHandle_; AuSPtr fsStream_; AuSPtr fsErrorHandle_; AuSPtr fsErrorStream_; AuThreadPrimitives::EventShared_t finished_; StartupParameters startup_; ESpawnType type_; AuList cargs_; AuString debug_; pid_t pidt_; bool alive_ {}; AuSInt exitCode_ {}; bool bHasExited {}; }; }