diff options
| author | Stefan Boberg <[email protected]> | 2021-06-20 17:02:29 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-06-20 17:02:29 +0200 |
| commit | 4d31e4138c0df916bcb7d2ac84a0f1854cfd073b (patch) | |
| tree | 04d42f0c40be2d6ce6ff248e85035a896004a526 | |
| parent | Improved some logging in test harness, added launcher test (diff) | |
| download | zen-4d31e4138c0df916bcb7d2ac84a0f1854cfd073b.tar.xz zen-4d31e4138c0df916bcb7d2ac84a0f1854cfd073b.zip | |
Launch sandbox directory is now dynamic and configured from the main server
Also added some debug logging
| -rw-r--r-- | zenserver/testing/launch.cpp | 36 | ||||
| -rw-r--r-- | zenserver/testing/launch.h | 13 | ||||
| -rw-r--r-- | zenserver/zenserver.cpp | 4 |
3 files changed, 38 insertions, 15 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 diff --git a/zenserver/testing/launch.h b/zenserver/testing/launch.h index 5dd946eda..00f322624 100644 --- a/zenserver/testing/launch.h +++ b/zenserver/testing/launch.h @@ -5,6 +5,7 @@ #include <zencore/httpserver.h> #include <spdlog/spdlog.h> +#include <filesystem> namespace zen { @@ -16,16 +17,20 @@ class CasStore; class HttpLaunchService : public HttpService { public: - HttpLaunchService(CasStore& Store); + HttpLaunchService(CasStore& Store, const std::filesystem::path& SandboxBaseDir); ~HttpLaunchService(); virtual const char* BaseUri() const override; virtual void HandleRequest(HttpServerRequest& Request) override; private: - spdlog::logger m_Log; - HttpRequestRouter m_Router; - CasStore& m_CasStore; + spdlog::logger m_Log; + HttpRequestRouter m_Router; + CasStore& m_CasStore; + std::filesystem::path m_SandboxPath; + std::atomic<int> m_SandboxCount{0}; + + std::filesystem::path CreateNewSandbox(); }; } // namespace zen diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp index c0b0dddec..f1db8676b 100644 --- a/zenserver/zenserver.cpp +++ b/zenserver/zenserver.cpp @@ -96,7 +96,9 @@ public: m_HttpProjectService.reset(new zen::HttpProjectService{*m_CasStore, m_ProjectStore}); m_LocalProjectService = zen::LocalProjectService::New(*m_CasStore, m_ProjectStore); - m_HttpLaunchService = std::make_unique<zen::HttpLaunchService>(*m_CasStore); + std::filesystem::path SandboxDir = m_DataRoot / "exec" / "sandbox"; + zen::CreateDirectories(SandboxDir); + m_HttpLaunchService = std::make_unique<zen::HttpLaunchService>(*m_CasStore, SandboxDir); m_CidStore = std::make_unique<zen::CidStore>(*m_CasStore, m_DataRoot / "cid"); |