2021-06-27 21:25:29 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
2022-11-17 07:46:07 +00:00
|
|
|
File: AuProcess.Unix.hpp
|
2021-06-27 21:25:29 +00:00
|
|
|
File: Process.Linux.hpp
|
|
|
|
Date: 2021-6-12
|
|
|
|
Author: Reece
|
|
|
|
***/
|
2022-05-04 19:34:46 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-06-12 13:53:35 +00:00
|
|
|
#include <Source/IO/Loop/LSEvent.hpp>
|
2022-05-04 19:34:46 +00:00
|
|
|
|
|
|
|
#include <Source/IO/FS/FS.hpp>
|
|
|
|
#if defined(AURORA_IS_LINUX_DERIVED)
|
|
|
|
#include <Source/IO/UNIX/IOSubmit.Linux.hpp>
|
|
|
|
#include <Source/IO/FS/Async.Linux.hpp>
|
|
|
|
using ProcessPipeFileStream = Aurora::IO::FS::LinuxAsyncFileStream;
|
|
|
|
#else
|
|
|
|
#include <Source/IO/FS/Async.Unix.hpp>
|
|
|
|
using ProcessPipeFileStream = Aurora::IO::FS::UnixAsyncFileStream;
|
|
|
|
#endif
|
2022-04-05 10:11:19 +00:00
|
|
|
|
|
|
|
namespace Aurora::Processes
|
|
|
|
{
|
|
|
|
void DeinitUnix();
|
|
|
|
void InitUnix();
|
2022-04-05 10:18:35 +00:00
|
|
|
|
2022-05-12 08:04:32 +00:00
|
|
|
struct ProcessImpl : IProcess
|
2022-04-05 10:18:35 +00:00
|
|
|
{
|
2023-08-21 16:48:42 +00:00
|
|
|
ProcessImpl(StartupParameters &¶ms);
|
2022-04-05 10:18:35 +00:00
|
|
|
~ProcessImpl();
|
|
|
|
|
|
|
|
void ShutdownPipes();
|
|
|
|
|
2023-12-24 06:22:58 +00:00
|
|
|
bool HasExited() override;
|
2022-04-05 10:18:35 +00:00
|
|
|
bool TryKill() override;
|
|
|
|
bool Terminate() override;
|
2022-05-04 19:34:46 +00:00
|
|
|
AuSPtr<Threading::IWaitable> AsWaitable() override;
|
2022-06-12 13:53:35 +00:00
|
|
|
AuSPtr<IO::Loop::ILoopSource> AsLoopSource() override;
|
2022-04-05 10:18:35 +00:00
|
|
|
|
|
|
|
AuSInt GetExitCode() override;
|
|
|
|
|
|
|
|
AuUInt GetProcessId() override;
|
|
|
|
|
|
|
|
bool Read(EStandardHandle stream, const AuMemoryViewStreamWrite &destination, bool nonblock) override;
|
|
|
|
bool Write(const AuMemoryViewStreamRead &source) override;
|
|
|
|
|
2022-05-12 08:04:32 +00:00
|
|
|
AuSPtr<IO::IAsyncTransaction> NewAsyncTransaction() override;
|
|
|
|
AuSPtr<IO::IAsyncTransaction> NewErrorStreamAsyncTransaction() override;
|
2023-09-16 21:08:10 +00:00
|
|
|
AuSPtr<IO::IIOHandle> GetOutputAndInputHandles() override;
|
|
|
|
AuSPtr<IO::IIOHandle> GetErrorStreamHandle() override;
|
2022-05-04 15:34:02 +00:00
|
|
|
|
2023-12-02 16:40:58 +00:00
|
|
|
AuSPtr<IO::IStreamReader> ToStreamReader(EStandardHandle stream) override;
|
|
|
|
AuSPtr<IO::IStreamWriter> ToStreamWriter() override;
|
|
|
|
|
2022-04-05 10:18:35 +00:00
|
|
|
bool Start() override;
|
|
|
|
|
|
|
|
bool Init();
|
|
|
|
|
|
|
|
void ByeLol(AuSInt code);
|
2022-08-10 15:04:41 +00:00
|
|
|
void ForkMain();
|
|
|
|
|
2023-12-23 03:56:09 +00:00
|
|
|
void HookMainDeath();
|
2022-04-05 10:18:35 +00:00
|
|
|
private:
|
|
|
|
|
2023-09-14 23:11:14 +00:00
|
|
|
int pipeStdOut_[2] { -1, -1 };
|
|
|
|
int pipeStdErr_[2] { -1, -1 };
|
|
|
|
int pipeStdIn_ [2] { -1, -1 };
|
2022-04-05 10:18:35 +00:00
|
|
|
|
2022-06-23 12:25:20 +00:00
|
|
|
bool bDontRelOut_ {};
|
|
|
|
bool bDontRelIn_ {};
|
|
|
|
bool bDontRelErr_ {};
|
|
|
|
|
2022-06-12 13:53:35 +00:00
|
|
|
AuSPtr<IO::Loop::ILSEvent> loopSource_;
|
2022-05-04 19:34:46 +00:00
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
AuSPtr<IO::IIOHandle> fsHandle_;
|
2022-05-04 19:34:46 +00:00
|
|
|
AuSPtr<ProcessPipeFileStream> fsStream_;
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
AuSPtr<IO::IIOHandle> fsErrorHandle_;
|
2022-05-04 19:34:46 +00:00
|
|
|
AuSPtr<ProcessPipeFileStream> fsErrorStream_;
|
|
|
|
|
2022-04-05 10:18:35 +00:00
|
|
|
AuThreadPrimitives::EventShared_t finished_;
|
|
|
|
|
2023-08-21 16:48:42 +00:00
|
|
|
StartupParameters startup_;
|
2022-04-05 10:18:35 +00:00
|
|
|
ESpawnType type_;
|
|
|
|
|
|
|
|
AuList<const char *> cargs_;
|
|
|
|
AuString debug_;
|
|
|
|
|
|
|
|
pid_t pidt_;
|
|
|
|
bool alive_ {};
|
|
|
|
|
2023-12-24 06:22:58 +00:00
|
|
|
AuSInt exitCode_ {};
|
|
|
|
bool bHasExited {};
|
2022-04-05 10:18:35 +00:00
|
|
|
};
|
2022-04-05 10:11:19 +00:00
|
|
|
}
|