libcryfs/test/fspp/testutils/FuseThread.cpp
Sebastian Messmer 40c64a879c Hide fuse quirks inside the Fuse class.
fuse_main needs the program arguments as char ** instead of const char ** or (even better) vector<string>.
With this commit, we hide that inside the Fuse class. Everything outside handles these arguments as vector<string> and passes it as such to the Fuse class.
2016-05-09 16:07:02 -07:00

40 lines
1.2 KiB
C++

#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "FuseThread.h"
#include <csignal>
#include <cpp-utils/assert/assert.h>
#include "fspp/fuse/Fuse.h"
using boost::thread;
using boost::chrono::seconds;
using std::string;
using std::vector;
namespace bf = boost::filesystem;
using fspp::fuse::Fuse;
FuseThread::FuseThread(Fuse *fuse)
:_fuse(fuse), _child() {
}
void FuseThread::start(const bf::path &mountDir, const vector<string> &fuseOptions) {
_child = thread([this, mountDir, fuseOptions] () {
_fuse->run(mountDir, fuseOptions);
});
//Wait until it is running (busy waiting is simple and doesn't hurt much here)
while(!_fuse->running()) {}
#ifdef __APPLE__
// On Mac OS X, _fuse->running() returns true too early, because osxfuse calls init() when it's not ready yet. Give it a bit time.
std::this_thread::sleep_for(std::chrono::milliseconds(200));
#endif
}
void FuseThread::stop() {
pthread_kill(_child.native_handle(), SIGINT);
bool thread_stopped = _child.try_join_for(seconds(5));
ASSERT(thread_stopped, "FuseThread could not be stopped");
//Wait until it is properly shutdown (busy waiting is simple and doesn't hurt much here)
while (_fuse->running()) {}
}