From 4d31e4138c0df916bcb7d2ac84a0f1854cfd073b Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Sun, 20 Jun 2021 17:02:29 +0200 Subject: Launch sandbox directory is now dynamic and configured from the main server Also added some debug logging --- zenserver/testing/launch.cpp | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'zenserver/testing/launch.cpp') 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(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 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 -- cgit v1.2.3