aboutsummaryrefslogtreecommitdiff
path: root/zenserver/testing/launch.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-06-20 17:02:29 +0200
committerStefan Boberg <[email protected]>2021-06-20 17:02:29 +0200
commit4d31e4138c0df916bcb7d2ac84a0f1854cfd073b (patch)
tree04d42f0c40be2d6ce6ff248e85035a896004a526 /zenserver/testing/launch.cpp
parentImproved some logging in test harness, added launcher test (diff)
downloadzen-4d31e4138c0df916bcb7d2ac84a0f1854cfd073b.tar.xz
zen-4d31e4138c0df916bcb7d2ac84a0f1854cfd073b.zip
Launch sandbox directory is now dynamic and configured from the main server
Also added some debug logging
Diffstat (limited to 'zenserver/testing/launch.cpp')
-rw-r--r--zenserver/testing/launch.cpp36
1 files changed, 26 insertions, 10 deletions
diff --git a/zenserver/testing/launch.cpp b/zenserver/testing/launch.cpp
index 2f8f40035..d06fae3e2 100644
--- a/zenserver/testing/launch.cpp
+++ b/zenserver/testing/launch.cpp
@@ -35,7 +35,7 @@ public:
void SetWorkingDirectory(const std::filesystem::path& WorkingDirectory) { m_WorkingDirectory = WorkingDirectory; }
bool SpawnJob(std::filesystem::path ExePath, std::wstring CommandLine);
bool Wait(uint32_t TimeoutMs = ~0);
- int ExitCode();
+ int ExitCode();
private:
std::filesystem::path m_WorkingDirectory;
@@ -107,11 +107,11 @@ BasicJob::Wait(uint32_t TimeoutMs)
throw std::exception("Failed wait on process handle");
}
-int
+int
BasicJob::ExitCode()
{
- DWORD Ec =0;
- BOOL Success = GetExitCodeProcess(m_ProcessHandle, &Ec);
+ DWORD Ec = 0;
+ BOOL Success = GetExitCodeProcess(m_ProcessHandle, &Ec);
if (!Success)
{
@@ -126,7 +126,6 @@ BasicJob::ExitCode()
return gsl::narrow_cast<int>(Ec);
}
-
struct SandboxedJob
{
SandboxedJob() = default;
@@ -317,9 +316,10 @@ SandboxedJob::SpawnJob(std::filesystem::path ExePath)
return true;
}
-HttpLaunchService::HttpLaunchService(CasStore& Store)
+HttpLaunchService::HttpLaunchService(CasStore& Store, const std::filesystem::path& SandboxBaseDir)
: m_Log("exec", begin(spdlog::default_logger()->sinks()), end(spdlog::default_logger()->sinks()))
, m_CasStore(Store)
+, m_SandboxPath(SandboxBaseDir)
{
m_Router.AddPattern("job", "([[:digit:]]+)");
@@ -435,8 +435,10 @@ HttpLaunchService::HttpLaunchService(CasStore& Store)
std::vector<IoHash> NeedList;
- // TODO: auto-generate!
- std::filesystem::path SandboxDir{"c:\\temp\\sandbox1"};
+ std::filesystem::path SandboxDir{CreateNewSandbox()};
+
+ spdlog::debug("setting up job in sandbox '{}'", SandboxDir);
+
zen::DeleteDirectories(SandboxDir);
zen::CreateDirectories(SandboxDir);
@@ -471,8 +473,13 @@ HttpLaunchService::HttpLaunchService(CasStore& Store)
return HttpReq.WriteResponse(HttpResponse::NotFound);
}
- std::wstring Executable = Utf8ToWide(RequestObject["cmd"].AsString());
- std::wstring Args = Utf8ToWide(RequestObject["args"].AsString());
+ std::string Executable8{RequestObject["cmd"].AsString()};
+ std::string Args8{RequestObject["args"].AsString()};
+
+ std::wstring Executable = Utf8ToWide(Executable8);
+ std::wstring Args = Utf8ToWide(Args8);
+
+ spdlog::debug("spawning job in sandbox '{}': '{}' '{}'", SandboxDir, Executable8, Args8);
std::filesystem::path ExeName = SandboxDir / Executable;
@@ -512,4 +519,13 @@ HttpLaunchService::HandleRequest(HttpServerRequest& Request)
}
}
+std::filesystem::path
+HttpLaunchService::CreateNewSandbox()
+{
+ std::string UniqueId = std::to_string(++m_SandboxCount);
+ std::filesystem::path Path = m_SandboxPath / UniqueId;
+ zen::CreateDirectories(Path);
+ return Path;
+}
+
} // namespace zen