[*] Made AuOpen.Unix.cpp in parity with Windows in that all IO should be deferred off the calling thread

This commit is contained in:
Reece Wilson 2023-09-19 00:40:00 +01:00
parent 746f39f848
commit 125c150fc5

View File

@ -14,48 +14,81 @@
namespace Aurora::Processes
{
static void UnixOpenAsync(const AuString &open)
static void UnixOpenAsyncThread(const AuString &uri, bool bType)
{
// TODO: MacOS is special. This will break IPC and the process binary is 'open'
if (fork() == 0)
{
setsid();
execl("xdg-open", open.c_str());
}
}
AUKN_SYM void OpenUri(const AuString &uri)
{
if (AuFS::FileExists(uri))
{
SysPushErrorGeneric("Exploit attempt? Attempted to open existing file/directory via URI ({})", uri);
return;
}
UnixOpenAsync(uri);
}
AUKN_SYM void OpenFile(const AuString &file)
{
auto path = AuIOFS::NormalizePathRet(file);
bool bDirExists {};
bool bFileExists {};
if (!(bFileExists = AuFS::FileExists(path)) &&
!AuFS::DirExists(path))
bFileExists = AuIOFS::FileExists(uri);
if (!bType)
{
SysPushErrorGeneric("Exploit attempt? Attempted to open non-existent file/directory. (request: {})", file);
bDirExists = AuIOFS::DirExists(uri);
if (!bFileExists &&
!bDirExists)
{
SysPushErrorGeneric("Exploit attempt? Attempted to open non-existent file/directory. (request: {})", uri);
return;
}
if (bFileExists)
{
if (!AuFS::IsFileBlocked(path))
if (!AuFS::IsFileBlocked(uri))
{
SysPushErrorGeneric("Exploit attempt? Attempted to open untrusted file/directory. (request: {})", file);
SysPushErrorGeneric("Exploit attempt? Attempted to open untrusted file/directory. (request: {})", uri);
return;
}
}
}
else
{
if (bFileExists)
{
SysPushErrorGeneric("Exploit attempt? Attempted to open existing file/directory via URI ({})", uri);
return;
}
}
UnixOpenAsync(path);
// TODO: MacOS is special. This will break IPC and the process binary is 'open'
if (fork() == 0)
{
setsid();
execl("xdg-open", uri.c_str());
exit(0);
}
}
static void UnixOpenAsync(const AuString &uri, bool bType)
{
if (uri.empty())
{
return;
}
// TODO: No, just no.
auto thread = AuThreads::ThreadUnique(AuThreads::ThreadInfo(
AuMakeShared<AuThreads::IThreadVectorsFunctional>(AuThreads::IThreadVectorsFunctional::OnEntry_t(std::bind(std::bind(&UnixOpenAsyncThread, uri, bType))),
AuThreads::IThreadVectorsFunctional::OnExit_t{})
));
if (!thread)
{
SysPushErrorGeneric("no resource");
return;
}
thread->Run();
thread->Detach();
}
AUKN_SYM void OpenUri(const AuString &uri)
{
UnixOpenAsync(uri, true);
}
AUKN_SYM void OpenFile(const AuString &file)
{
UnixOpenAsync(file, false);
}
}