diff --git a/src/main.cpp b/src/main.cpp index dd258984..f6f23304 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "messmer/fspp/fuse/Fuse.h" #include "messmer/fspp/impl/FilesystemImpl.h" @@ -27,7 +28,6 @@ using std::endl; using std::vector; //TODO Support files > 4GB -//TODO cryfs process doesn't seem to react to "kill". Needs "kill -9". Why? Furthermore, calling "fusermount -u" unmounts the fs, but the cryfs process keeps running. Why? //TODO Improve parallelity. //TODO Seems to deadlock in bonnie++ second run (in the create files sequentially) - maybe also in a later run or different step? @@ -58,9 +58,13 @@ void runFilesystem(const ProgramOptions &options) { int main(int argc, char *argv[]) { cpputils::showBacktraceOnSigSegv(); - showVersion(); + ProgramOptions options = program_options::Parser(argc, argv).parse(); + if (!options.foreground()) { + cpputils::daemonize(); + } + runFilesystem(options); return 0; } diff --git a/src/program_options/Parser.cpp b/src/program_options/Parser.cpp index da8be61f..4ef86fd4 100644 --- a/src/program_options/Parser.cpp +++ b/src/program_options/Parser.cpp @@ -26,8 +26,9 @@ ProgramOptions Parser::parse() const { string baseDir = vm["base-dir"].as(); string mountDir = vm["mount-dir"].as(); string configFile = vm["config"].as(); + bool foreground = vm.count("foreground"); - return ProgramOptions(baseDir, mountDir, configFile, options.second); + return ProgramOptions(baseDir, mountDir, configFile, foreground, options.second); } po::variables_map Parser::_parseOptionsOrShowHelp(const vector options) { @@ -60,6 +61,7 @@ void Parser::_addAllowedOptions(po::options_description *desc) { options.add_options() ("help,h", "show help message") ("config,c", po::value()->required(), "Config file") + ("foreground,f", "Run CryFS in foreground.") ; desc->add(options); } diff --git a/src/program_options/ProgramOptions.cpp b/src/program_options/ProgramOptions.cpp index 8d5aadbd..211704b6 100644 --- a/src/program_options/ProgramOptions.cpp +++ b/src/program_options/ProgramOptions.cpp @@ -6,8 +6,8 @@ using namespace cryfs::program_options; using std::string; using std::vector; -ProgramOptions::ProgramOptions(const string &baseDir, const string &mountDir, const std::string &configFile, const vector &fuseOptions) - :_baseDir(baseDir), _mountDir(new char[mountDir.size()+1]), _configFile(configFile), _fuseOptions(fuseOptions) { +ProgramOptions::ProgramOptions(const string &baseDir, const string &mountDir, const std::string &configFile, bool foreground, const vector &fuseOptions) + :_baseDir(baseDir), _mountDir(new char[mountDir.size()+1]), _configFile(configFile), _foreground(foreground), _fuseOptions(fuseOptions) { std::memcpy(_mountDir, mountDir.c_str(), mountDir.size()+1); // Fuse needs the mountDir passed as first option (first option = position 1, since 0 is the executable name) ASSERT(_fuseOptions.size() >= 1, "There has to be one parameter at least for the executable name"); @@ -30,6 +30,10 @@ const string &ProgramOptions::configFile() const { return _configFile; } +bool ProgramOptions::foreground() const { + return _foreground; +} + const vector &ProgramOptions::fuseOptions() const { return _fuseOptions; } diff --git a/src/program_options/ProgramOptions.h b/src/program_options/ProgramOptions.h index eabd240a..6d1b8d21 100644 --- a/src/program_options/ProgramOptions.h +++ b/src/program_options/ProgramOptions.h @@ -8,18 +8,20 @@ namespace cryfs { namespace program_options { class ProgramOptions { public: - ProgramOptions(const std::string &baseDir, const std::string &mountDir, const std::string &configFile, const std::vector &fuseOptions); + ProgramOptions(const std::string &baseDir, const std::string &mountDir, const std::string &configFile, bool foreground, const std::vector &fuseOptions); ~ProgramOptions(); const std::string &baseDir() const; std::string mountDir() const; const std::string &configFile() const; + bool foreground() const; const std::vector &fuseOptions() const; private: std::string _baseDir; char *_mountDir; std::string _configFile; + bool _foreground; std::vector _fuseOptions; }; }