Jamie Reece Wilson
83f34b0c47
03:28:55:638 17>2 of 53388 functions (<0.1%) were compiled, the rest were copied from previous compilation. 03:28:55:638 17> 0 functions were new in current compilation 03:28:55:638 17> 65 functions had inline decision re-evaluated but remain unchanged 03:28:56:749 17>Finished generating code the header of const AuString & is the same as std::string_view therefore nothing changes. in fact, we still need to alloc strings a bunch of times for a zero terminated string. worse, <c++20 always allocs each time we want to access a hashmap with o(1) lookup, making small hashmaps kinda pointless when we always have to alloc+copy (thx std) perhaps this will help some language binders
125 lines
3.7 KiB
C++
125 lines
3.7 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: AuOpen.Unix.cpp
|
|
Date: 2021-6-12
|
|
Author: Reece
|
|
***/
|
|
#include <RuntimeInternal.hpp>
|
|
#include "AuProcesses.hpp"
|
|
#include "AuOpen.Unix.hpp"
|
|
|
|
#include <unistd.h>
|
|
#include <Source/IO/FS/FS.hpp>
|
|
|
|
namespace Aurora::Processes
|
|
{
|
|
static void UnixOpenAsyncThread(AuString uri, bool bType)
|
|
{
|
|
bool bDirExists {};
|
|
bool bFileExists {};
|
|
|
|
bFileExists = AuIOFS::FileExists(uri);
|
|
|
|
if (!bType)
|
|
{
|
|
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(uri))
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
|
|
if constexpr (AuBuild::kIsXnuDerived)
|
|
{
|
|
// TODO: MacOS/iOS support
|
|
}
|
|
else
|
|
{
|
|
if (fork() == 0)
|
|
{
|
|
setsid();
|
|
|
|
PosixDoForkHooks();
|
|
PosixShutup();
|
|
PosixFDYeetus();
|
|
|
|
auto optStringA = AuProcess::EnvironmentGetOne("container");
|
|
auto optStringB = AuProcess::EnvironmentGetOne("AURORA_RUNTIME_USE_GDBUS_BIN_TO_PORTAL");
|
|
bool bIsFireJail = optStringA && optStringA.Value() == "firejail";
|
|
bool bIsForcedDBUS = optStringB && optStringB.Value() == "YES";
|
|
if (bIsFireJail || bIsForcedDBUS)
|
|
{
|
|
execlp("gdbus",
|
|
"gdbus",
|
|
"call",
|
|
"--session",
|
|
"--dest", "org.freedesktop.portal.Desktop",
|
|
"--object-path", "/org/freedesktop/portal/desktop",
|
|
"--method", bFileExists ? "org.freedesktop.portal.OpenURI.OpenFile" : "org.freedesktop.portal.OpenURI.OpenURI",
|
|
"",
|
|
uri.c_str(),
|
|
"{}",
|
|
(char *)nullptr);
|
|
}
|
|
else
|
|
{
|
|
if (AuFS::FileExists("/usr/bin/xdg-open"))
|
|
{
|
|
execl("/usr/bin/xdg-open", "xdg-open", uri.c_str(), (char *)nullptr);
|
|
}
|
|
else if (AuFS::FileExists("/usr/local/bin/xdg-open"))
|
|
{
|
|
execl("/usr/local/bin/xdg-open", "xdg-open", uri.c_str(), (char *)nullptr);
|
|
}
|
|
else
|
|
{
|
|
execlp("xdg-open", "xdg-open", uri.c_str(), (char *)nullptr);
|
|
}
|
|
}
|
|
|
|
exit(0);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void UnixOpenAsync(const AuROString &uri, bool bType)
|
|
{
|
|
if (uri.empty())
|
|
{
|
|
return;
|
|
}
|
|
|
|
AuThreads::Spawn(std::bind(&UnixOpenAsyncThread, AuString(uri), bType), true);
|
|
}
|
|
|
|
AUKN_SYM void OpenUri(const AuROString &uri)
|
|
{
|
|
UnixOpenAsync(uri, true);
|
|
}
|
|
|
|
AUKN_SYM void OpenFile(const AuROString &file)
|
|
{
|
|
UnixOpenAsync(file, false);
|
|
}
|
|
} |