diff --git a/spectrum/src/main.cpp b/spectrum/src/main.cpp index a55a5ad9e31a44e27951c90d72fc9f8ad8215b8f..5afdeb1921d1dddfed14ec5982dcc6cd5b81fecf 100644 --- a/spectrum/src/main.cpp +++ b/spectrum/src/main.cpp @@ -8,6 +8,7 @@ #include "transport/networkpluginserver.h" #include "transport/admininterface.h" #include "Swiften/EventLoop/SimpleEventLoop.h" +#include #ifndef WIN32 #include "sys/signal.h" #else @@ -18,6 +19,7 @@ #include "log4cxx/patternlayout.h" #include "log4cxx/propertyconfigurator.h" #include "log4cxx/consoleappender.h" +#include "libgen.h" using namespace log4cxx; @@ -161,7 +163,23 @@ int main(int argc, char **argv) #ifndef WIN32 if (!no_daemon) { - daemonize("/", NULL); + try { + boost::filesystem::create_directories(CONFIG_STRING(&config, "service.working_dir")); + } + catch (...) { + std::cerr << "Can't create service.working_dir directory " << CONFIG_STRING(&config, "service.working_dir") << ".\n"; + return 1; + } + try { + boost::filesystem::create_directories( + boost::filesystem::path(CONFIG_STRING(&config, "service.pidfile")).parent_path().string() + ); + } + catch (...) { + std::cerr << "Can't create service.pidfile directory " << boost::filesystem::path(CONFIG_STRING(&config, "service.pidfile")).parent_path().string() << ".\n"; + return 1; + } + daemonize(CONFIG_STRING(&config, "service.working_dir").c_str(), CONFIG_STRING(&config, "service.pidfile").c_str()); } #endif