[*] Linux has a pulse...

This commit is contained in:
Reece Wilson 2022-04-06 02:24:38 +01:00
parent 3205ea8a1f
commit 8fe83de42f
7 changed files with 86 additions and 36 deletions

View File

@ -198,8 +198,8 @@ namespace Aurora::Console::ConsoleStd
#endif #endif
SysAssert(gInputStream, "Couldn't allocate input stream handler"); SysAssert(gInputStream != DEFAULT_HANDLE_VAL, "Couldn't allocate input stream handler");
SysAssert(gOutputStream, "Couldn't allocate output stream handler"); SysAssert(gOutputStream != DEFAULT_HANDLE_VAL, "Couldn't allocate output stream handler");
StartLogger(); StartLogger();
} }

View File

@ -5,3 +5,13 @@
Date: 2021-6-12 Date: 2021-6-12
Author: Reece Author: Reece
***/ ***/
#include <Source/RuntimeInternal.hpp>
#include "ExceptionWatcher.Unix.hpp"
namespace Aurora::Debug
{
void PlatformHandleFatal(bool fatal)
{
}
}

View File

@ -38,19 +38,19 @@ namespace Aurora::IO::FS
return IterateDirEntriesSTL(string, false, dirs); return IterateDirEntriesSTL(string, false, dirs);
} }
AUKN_SYM bool WriteFile(const AuString &path, const void *data, AuUInt length) AUKN_SYM bool WriteFile(const AuString &path, const Memory::MemoryViewRead &blob)
{ {
auto file = OpenWriteUnique(path); auto file = OpenWriteUnique(path);
SysCheckReturn(file, false); SysCheckReturn(file, false);
AuUInt written = length; AuUInt written = blob.length;
if (!file->Write(Memory::MemoryViewStreamRead(data, written))) if (!file->Write(Memory::MemoryViewStreamRead(blob, written)))
{ {
SysPushErrorMem(); SysPushErrorMem();
return false; return false;
} }
if (written != length) if (written != blob.length)
{ {
SysPushErrorIO(); SysPushErrorIO();
return false; return false;
@ -59,32 +59,48 @@ namespace Aurora::IO::FS
return false; return false;
} }
AUKN_SYM bool ReadFile(const AuString &path, AuList<uint8_t> &buffer) AUKN_SYM bool ReadFile(const AuString &path, AuByteBuffer &buffer)
{ {
AuUInt read;
auto file = OpenReadUnique(path); auto file = OpenReadUnique(path);
SysCheckReturn(file, false); SysCheckReturn(file, false);
auto len = file->GetLength(); auto len = file->GetLength();
// NOTE: Linux file systems are such a cluster fuck of unimplemented interface
// It's not unusual for these sockets to be unstreamable across NIX-like oses
if (len == 0)
{
if (AuStartsWith(path, "/proc/") ||
AuStartsWith(path, "/sys/") ||
AuStartsWith(path, "/dev/"))
{
len = 4096;
}
else
{
buffer.clear();
return true;
}
}
if (!AuTryResize(buffer, len)) if (!AuTryResize(buffer, len))
{ {
SysPushErrorMem(); SysPushErrorMem();
return false; return false;
} }
AuUInt read; if (!file->Read(Memory::MemoryViewStreamWrite {buffer.begin(), buffer.end(), read}))
if (!file->Read(Memory::MemoryViewStreamWrite {buffer, read}))
{ {
SysPushErrorIO(); SysPushErrorIO();
return false; return false;
} }
// NOTE: File devices love to lie
// Do not entertain an arbitrarily large page length provided by non-regular fds
if (read != buffer.size()) return AuTryResize(buffer, read);
{
SysPushErrorIO();
return false;
}
return false;
} }
static bool UnixExists(const AuString &path, bool dir) static bool UnixExists(const AuString &path, bool dir)

View File

@ -101,7 +101,7 @@ namespace Aurora::IO::FS
return true; return true;
} }
static bool PosixWrite(int fd, const void *buf, AuUInt32 count, AuUInt32 *pWritten) static bool PosixWrite(int fd, const void *buf, AuUInt32 count, AuUInt32 *pWritten)
{ {
auto ret = write(fd, buf, count); auto ret = write(fd, buf, count);
@ -294,16 +294,17 @@ namespace Aurora::IO::FS
this->bMadeTemporary = true; this->bMadeTemporary = true;
} }
static IFileStream *OpenNew(const AuString &path, bool read) static IFileStream *OpenNew(const AuString &path, EFileOpenMode openMode, EFileAdvisoryLockLevel lock)
{ {
auto pathex = NormalizePathRet(path); auto pathex = NormalizePathRet(path);
if (!read) if (openMode != EFileOpenMode::eRead)
{ {
CreateDirectories(pathex, true); CreateDirectories(pathex, true);
} }
auto fileHandle = open(pathex.c_str(), read ? O_RDONLY : O_RDWR); auto fileHandle = open(pathex.c_str(),
openMode == EFileOpenMode::eRead ? O_RDONLY : O_RDWR);
if (fileHandle < 0) if (fileHandle < 0)
{ {
@ -315,34 +316,41 @@ namespace Aurora::IO::FS
if (!stream) if (!stream)
{ {
::close(fileHandle); ::close(fileHandle);
SysPushErrorMem("{}", path);
return nullptr; return nullptr;
} }
if (!stream->Init(fileHandle, pathex)) if (!stream->Init(fileHandle, pathex))
{ {
delete stream; delete stream;
SysPushErrorGeneric("{}", path);
return nullptr; return nullptr;
} }
return stream; return stream;
} }
AUKN_SYM IFileStream *OpenReadNew(const AuString &path) AUKN_SYM void OpenRelease(IFileStream *that)
{
return OpenNew(path, true);
}
AUKN_SYM void OpenReadRelease(IFileStream *that)
{ {
AuSafeDelete<PosixFileStream *>(that); AuSafeDelete<PosixFileStream *>(that);
} }
AUKN_SYM IFileStream *OpenWriteNew(const AuString &path) AUKN_SYM IFileStream *OpenReadNew(const AuString &path, EFileAdvisoryLockLevel level)
{ {
return OpenNew(path, false); return OpenNew(path, EFileOpenMode::eRead, level);
} }
AUKN_SYM void OpenWriteRelease(IFileStream * that) AUKN_SYM void OpenReadRelease(IFileStream * that)
{
AuSafeDelete<PosixFileStream *>(that);
}
AUKN_SYM IFileStream *OpenWriteNew(const AuString &path, EFileAdvisoryLockLevel level)
{
return OpenNew(path, EFileOpenMode::eWrite, level);
}
AUKN_SYM void OpenWriteRelease(IFileStream *that)
{ {
AuSafeDelete<PosixFileStream *>(that); AuSafeDelete<PosixFileStream *>(that);
} }

View File

@ -92,9 +92,9 @@ namespace Aurora::Loop
return ELoopSource::eSourceEvent; return ELoopSource::eSourceEvent;
} }
AUKN_SYM AuSPtr<ILSEvent> NewLSEvent() AUKN_SYM AuSPtr<ILSEvent> NewLSEvent(bool triggered, bool atomicRelease, bool permitMultipleTriggers)
{ {
auto event = AuMakeShared<LSEvent>(); auto event = AuMakeShared<LSEvent>(triggered, atomicRelease, permitMultipleTriggers);
if (!event) if (!event)
{ {
return {}; return {};

View File

@ -330,12 +330,25 @@ namespace Aurora::Processes
void InitUnix() void InitUnix()
{ {
signal(SIGCHLD, SigChldHandler);
gRWLock = AuThreadPrimitives::RWLockUnique(); gRWLock = AuThreadPrimitives::RWLockUnique();
struct sigaction action =
{
.sa_handler = SigChldHandler,
.sa_flags = SA_ONSTACK
};
sigaction(SIGCHLD, &action, nullptr);
} }
void DeinitUnix() void DeinitUnix()
{ {
struct sigaction action =
{
.sa_handler = SIG_DFL,
.sa_flags = SA_ONSTACK | SA_NOCLDWAIT
};
sigaction(SIGCHLD, &action, nullptr);
gRWLock.reset(); gRWLock.reset();
} }
} }

View File

@ -12,26 +12,29 @@
namespace Aurora::Telemetry namespace Aurora::Telemetry
{ {
static bool bHasInit {};
static AuThreadPrimitives::CriticalSectionUnique_t gGroupLock; static AuThreadPrimitives::CriticalSectionUnique_t gGroupLock;
void BeginBlock() void BeginBlock()
{ {
if (!bHasInit) return;
gGroupLock->Lock(); gGroupLock->Lock();
} }
void EndBlock() void EndBlock()
{ {
if (!bHasInit) return;
gGroupLock->Unlock(); gGroupLock->Unlock();
} }
void InsertOSError(const Debug::OSError_t &osError) void InsertOSError(const Debug::OSError_t &osError)
{ {
if (!bHasInit) return;
} }
void InsertMsgError(const Debug::LastError &error) void InsertMsgError(const Debug::LastError &error)
{ {
if (!bHasInit) return;
} }
void InsertCError(AuSInt cError) void InsertCError(AuSInt cError)