Don't let FUSE do daemonization, because it won't fork other threads than the main thread. Force applications to do daemonization themselves.

This commit is contained in:
Sebastian Meßmer 2015-10-15 03:41:02 +02:00
parent 6d5c3aab4c
commit c150c66534
2 changed files with 19 additions and 1 deletions

View File

@ -7,6 +7,7 @@
#include <iostream>
#include <messmer/cpp-utils/assert/assert.h>
using std::vector;
using std::string;
namespace bf = boost::filesystem;
@ -214,7 +215,22 @@ Fuse::Fuse(Filesystem *fs)
}
void Fuse::run(int argc, char **argv) {
fuse_main(argc, argv, operations(), (void*)this);
vector<char*> _argv(argv, argv + argc);
//If we allow fuse to fork the process, it wouldn't fork our threads with it (fork() only forks the main thread).
//So we always run it in foreground, and can do our own daemonization before calling this.
_addRunInForegroundOption(&_argv);
fuse_main(_argv.size(), _argv.data(), operations(), (void*)this);
}
void Fuse::_addRunInForegroundOption(vector<char*> *argv) {
//TODO Fix char* warning (-Wwrite-strings)
static char *foregroundOption = "-f";
bool hasRunInForegroundOption = std::find_if(argv->begin(), argv->end(),
[] (char *elem) {return string(elem) == string(foregroundOption);}
) != argv->end();
if (!hasRunInForegroundOption) {
argv->push_back(foregroundOption);
}
}
bool Fuse::running() const {

View File

@ -5,6 +5,7 @@
#include "params.h"
#include <cstdio>
#include <string>
#include <vector>
#include <sys/stat.h>
#include <boost/filesystem.hpp>
#include "messmer/cpp-utils/macros.h"
@ -56,6 +57,7 @@ public:
private:
Filesystem *_fs;
void _addRunInForegroundOption(std::vector<char*> *argv);
bool _running;
DISALLOW_COPY_AND_ASSIGN(Fuse);