28 lines
636 B
C++
28 lines
636 B
C++
#pragma once
|
|||
|
|
#include <string>
|
||
|
|
#include <vector>
|
||
|
|
|
||
|
|
#include "container.hpp"
|
||
|
|
#include "util.hpp"
|
||
|
|
|
||
|
|
namespace doos {
|
||
|
|
|
||
|
|
// Runs a command inside a container: starts the namespaces if the container is
|
||
|
|
// stopped, joins them if it is already running. Returns the command's exit code.
|
||
|
|
class Sandbox {
|
||
|
|
public:
|
||
|
|
Sandbox(Container container, std::vector<std::string> command)
|
||
|
|
: container_(std::move(container)), command_(std::move(command)) {}
|
||
|
|
|
||
|
|
int run();
|
||
|
|
|
||
|
|
private:
|
||
|
|
int start(FileLock& lock);
|
||
|
|
int join(pid_t initPid, FileLock& lock);
|
||
|
|
|
||
|
|
Container container_;
|
||
|
|
std::vector<std::string> command_;
|
||
|
|
};
|
||
|
|
|
||
|
|
} // namespace doos
|