From fdf866a562c5774bfaa39f3d0cdbcdfdc04c811a Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Fri, 30 Oct 2015 21:40:38 +0100 Subject: [PATCH] Since fork() issue with our threads is solved, use libFuse damonization again --- src/Cli.cpp | 21 ++++++--------------- src/Cli.h | 1 - src/program_options/Parser.cpp | 3 +++ test/cli/testutils/CliTest.h | 2 +- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/Cli.cpp b/src/Cli.cpp index 57a456b3..713399e8 100644 --- a/src/Cli.cpp +++ b/src/Cli.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include "messmer/fspp/fuse/Fuse.h" #include "messmer/fspp/impl/FilesystemImpl.h" @@ -126,9 +125,7 @@ namespace cryfs { _initLogfile(options); - std::cout << "\nFilesystem is running. To unmount, call:\n$ fusermount -u " << options.mountDir() << "\n" << std::endl; - - _goToBackgroundIfSpecified(options); + std::cout << "\nMounting filesystem. To unmount, call:\n$ fusermount -u " << options.mountDir() << "\n" << std::endl; vector fuseOptions = options.fuseOptions(); fuse.run(fuseOptions.size(), fuseOptions.data()); @@ -139,21 +136,15 @@ namespace cryfs { } } - void Cli::_goToBackgroundIfSpecified(const ProgramOptions &options) { - if (!options.foreground()) { - cpputils::daemonize(); - if (options.logFile() == none) { - // Setup logging to syslog. - cpputils::logging::setLogger(spdlog::syslog_logger("cryfs", "cryfs", LOG_PID)); - } - } - } - void Cli::_initLogfile(const ProgramOptions &options) { //TODO Test that --logfile parameter works. Should be: file if specified, otherwise stderr if foreground, else syslog. if (options.logFile() != none) { cpputils::logging::setLogger( spdlog::create>("cryfs", *options.logFile())); + } else if (options.foreground()) { + cpputils::logging::setLogger(spdlog::stderr_logger_mt("cryfs")); + } else { + cpputils::logging::setLogger(spdlog::syslog_logger("cryfs", "cryfs", LOG_PID)); } } @@ -184,7 +175,7 @@ namespace cryfs { } void Cli::_checkBasedirReadable(const ProgramOptions &options, shared_ptr tempfile) { - ASSERT(bf::path(options.baseDir()) == tempfile->path().parent_path(), "This function should be called with a file inside the base directory"); + ASSERT(bf::equivalent(bf::path(options.baseDir()), tempfile->path().parent_path()), "This function should be called with a file inside the base directory"); try { bool found = false; bf::directory_iterator end; diff --git a/src/Cli.h b/src/Cli.h index f32a2600..44c011d3 100644 --- a/src/Cli.h +++ b/src/Cli.h @@ -16,7 +16,6 @@ namespace cryfs { static void _runFilesystem(const program_options::ProgramOptions &options); static CryConfigFile _loadOrCreateConfig(const program_options::ProgramOptions &options); static boost::filesystem::path _determineConfigFile(const program_options::ProgramOptions &options); - static void _goToBackgroundIfSpecified(const program_options::ProgramOptions &options); static std::string _askPassword(); static bool _checkPassword(const std::string &password); static void _showVersion(); diff --git a/src/program_options/Parser.cpp b/src/program_options/Parser.cpp index 8caf859c..9b08d078 100644 --- a/src/program_options/Parser.cpp +++ b/src/program_options/Parser.cpp @@ -36,6 +36,9 @@ ProgramOptions Parser::parse(const vector &supportedCiphers) const { configfile = vm["config"].as(); } bool foreground = vm.count("foreground"); + if (foreground) { + options.second.push_back(const_cast("-f")); + } optional logfile = none; if (vm.count("logfile")) { logfile = vm["logfile"].as(); diff --git a/test/cli/testutils/CliTest.h b/test/cli/testutils/CliTest.h index 1bec9b8f..c5ca1dd0 100644 --- a/test/cli/testutils/CliTest.h +++ b/test/cli/testutils/CliTest.h @@ -45,7 +45,7 @@ public: public: _UnmountFilesystemInDestructor(const boost::filesystem::path &baseDir) :_baseDir(baseDir) {} ~_UnmountFilesystemInDestructor() { - if (0 != system((std::string("fusermount -u ")+_baseDir.c_str()).c_str()), "Could not unmount cryfs") { + if (0 != system((std::string("fusermount -u ")+_baseDir.c_str()).c_str())) { cpputils::logging::LOG(cpputils::logging::ERROR) << "Could not unmount cryfs"; } }