mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 21:01:37 +00:00
Implement OS Restart on Linux. (#50)
This commit is contained in:
parent
290ee4e02c
commit
da245b60e3
1 changed files with 44 additions and 7 deletions
|
|
@ -1,20 +1,57 @@
|
||||||
#include <os/process_detail.h>
|
#include <os/process_detail.h>
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
std::filesystem::path os::process::detail::GetExecutablePath()
|
std::filesystem::path os::process::detail::GetExecutablePath()
|
||||||
{
|
{
|
||||||
assert(false && "Unimplemented.");
|
char exePath[PATH_MAX] = {};
|
||||||
return std::filesystem::path();
|
if (readlink("/proc/self/exe", exePath, PATH_MAX) > 0)
|
||||||
|
{
|
||||||
|
return std::filesystem::path(std::u8string_view((const char8_t*)(exePath)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return std::filesystem::path();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path os::process::detail::GetWorkingDirectory()
|
std::filesystem::path os::process::detail::GetWorkingDirectory()
|
||||||
{
|
{
|
||||||
// TODO: There's a cross platform way to retrieve this which is just getting it from argv[0].
|
char cwd[PATH_MAX] = {};
|
||||||
assert(false && "Unimplemented.");
|
char *res = getcwd(cwd, sizeof(cwd));
|
||||||
return std::filesystem::path();
|
if (res != nullptr)
|
||||||
|
{
|
||||||
|
return std::filesystem::path(std::u8string_view((const char8_t*)(cwd)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return std::filesystem::path();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool os::process::detail::StartProcess(const std::filesystem::path path, const std::vector<std::string> args, std::filesystem::path work)
|
bool os::process::detail::StartProcess(const std::filesystem::path path, const std::vector<std::string> args, std::filesystem::path work)
|
||||||
{
|
{
|
||||||
assert(false && "Unimplemented.");
|
pid_t pid = fork();
|
||||||
return false;
|
if (pid < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (pid == 0)
|
||||||
|
{
|
||||||
|
setsid();
|
||||||
|
|
||||||
|
std::u8string workU8 = work.u8string();
|
||||||
|
chdir((const char*)(workU8.c_str()));
|
||||||
|
|
||||||
|
std::u8string pathU8 = path.u8string();
|
||||||
|
std::vector<char*> argStrs;
|
||||||
|
argStrs.push_back((char*)(pathU8.c_str()));
|
||||||
|
for (const std::string& arg : args)
|
||||||
|
argStrs.push_back((char *)(arg.c_str()));
|
||||||
|
|
||||||
|
argStrs.push_back(nullptr);
|
||||||
|
execvp((const char*)(pathU8.c_str()), argStrs.data());
|
||||||
|
raise(SIGKILL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue