17 #ifndef __LINUX_NS_HPP__    18 #define __LINUX_NS_HPP__    22 #error "linux/ns.hpp is only available on Linux systems."    27 #include <sys/syscall.h>    43 #define CLONE_NEWNS 0x00020000    47 #define CLONE_NEWUTS 0x04000000    51 #define CLONE_NEWIPC 0x08000000    55 #define CLONE_NEWPID 0x20000000    59 #define CLONE_NEWNET 0x40000000    63 #define CLONE_NEWUSER 0x10000000    66 #ifndef CLONE_NEWCGROUP    67 #define CLONE_NEWCGROUP 0x02000000    75   return ::syscall(SYS_setns, fd, nstype);
    76 #elif defined(__x86_64__)    80   return ::syscall(308, fd, nstype);
    82 #error "setns is not available"   117     const std::string& 
path,
   118     const std::string& ns,
   119     bool checkMultithreaded = 
true);
   126     const std::string& ns,
   127     bool checkMultithreaded = 
true);
   178     const lambda::function<
int()>& 
f,
   196     thread.reset(
new std::thread(&NamespaceRunner::loop, 
this));
   209   template <
typename T>
   211       const std::string& path,
   212       const std::string& ns,
   213       const lambda::function<
Try<T>()>& func)
   215     std::shared_ptr<process::Promise<T>> 
promise(
   225         promise->fail(setns.
error());
   227         promise->set(func());
   235   typedef lambda::function<void()> Func;
   264   template <
typename T>
   265   class ProcessingQueue
   268     ProcessingQueue() : finished(
false) {}
   270     ~ProcessingQueue() = 
default;
   275       synchronized (mutex) {
   276         queue.push(std::forward<T>(t));
   286       synchronized (mutex) {
   288         while (queue.empty() && !finished) {
   298         T t = std::move(queue.front());
   300         return Some(std::move(t));
   306       synchronized (mutex) {
   308         std::queue<T>().swap(queue);
   315     std::condition_variable cond;
   320   ProcessingQueue<Func> queue;
   321   std::unique_ptr<std::thread> thread;
   326 #endif // __LINUX_NS_HPP__ process::Future< T > run(const std::string &path, const std::string &ns, const lambda::function< Try< T >()> &func)
Definition: ns.hpp:210
Definition: option.hpp:29
Try< pid_t > clone(pid_t target, int nstypes, const lambda::function< int()> &f, int flags)
Performs an os::clone after entering a set of namespaces for the specified target process...
Try< bool > supported(int nsTypes)
F && f
Definition: defer.hpp:270
int setns(int fd, int nstype)
Definition: ns.hpp:72
Try< std::string > nsname(int nsType)
Try< Nothing > setns(const std::string &path, const std::string &ns, bool checkMultithreaded=true)
void synchronized_wait(CV *cv, Lock *lock)
Waits on the condition variable associated with 'lock' which has already been synchronized. 
std::set< int > nstypes()
DWORD pid_t
Definition: windows.hpp:181
NamespaceRunner()
Definition: ns.hpp:193
~NamespaceRunner()
Definition: ns.hpp:199
Definition: future.hpp:74
const T & get() const &
Definition: option.hpp:119
Protocol< PromiseRequest, PromiseResponse > promise
static Try error(const E &e)
Definition: try.hpp:43
_Some< typename std::decay< T >::type > Some(T &&t)
Definition: some.hpp:42
bool isError() const 
Definition: try.hpp:78
Result< ino_t > getns(pid_t pid, const std::string &ns)
Try< int > nstype(const std::string &ns)
bool isNone() const 
Definition: option.hpp:117
std::string stringify(int flags)
Definition: future.hpp:58