diff --git a/src/logging.cpp b/src/logging.cpp index f724993ef91b34f51756ffe97573e1147bd6be39..a7f8478b090172d28f076dfeb8dd0de89c02f510 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -20,6 +20,7 @@ #include "transport/logging.h" #include "transport/config.h" +#include "transport/util.h" #include #include #include @@ -31,6 +32,7 @@ #ifndef WIN32 #include "sys/signal.h" +#include #include #include #include @@ -136,35 +138,42 @@ static void initLogging(Config *config, std::string key) { break; } } - + mode_t old_cmask; if (!dir.empty()) { // create directories +#ifndef WIN32 + old_cmask = umask(0007); +#endif try { - boost::filesystem::create_directories( - boost::filesystem::path(dir).parent_path().string() - ); + Transport::Util::createDirectories(config, boost::filesystem::path(dir).parent_path()); } - catch (...) { - std::cerr << "Can't create logging directory directory " << boost::filesystem::path(dir).parent_path().string() << ".\n"; + catch (const boost::filesystem::filesystem_error &e) { + std::cerr << "Can't create logging directory directory " << boost::filesystem::path(dir).parent_path().string() << ": " << e.what() << ".\n"; } + } -#ifndef WIN32 - if (!CONFIG_STRING(config, "service.group").empty() && !CONFIG_STRING(config, "service.user").empty()) { - struct group *gr; - if ((gr = getgrnam(CONFIG_STRING(config, "service.group").c_str())) == NULL) { - std::cerr << "Invalid service.group name " << CONFIG_STRING(config, "service.group") << "\n"; - } - struct passwd *pw; - if ((pw = getpwnam(CONFIG_STRING(config, "service.user").c_str())) == NULL) { - std::cerr << "Invalid service.user name " << CONFIG_STRING(config, "service.user") << "\n"; - } - chown(dir.c_str(), pw->pw_uid, gr->gr_gid); - } + log4cxx::PropertyConfigurator::configure(p); -#endif + // Change owner of main log file +#ifndef WIN32 + if (!CONFIG_STRING(config, "service.group").empty() && !CONFIG_STRING(config, "service.user").empty()) { + struct group *gr; + if ((gr = getgrnam(CONFIG_STRING(config, "service.group").c_str())) == NULL) { + std::cerr << "Invalid service.group name " << CONFIG_STRING(config, "service.group") << "\n"; } + struct passwd *pw; + if ((pw = getpwnam(CONFIG_STRING(config, "service.user").c_str())) == NULL) { + std::cerr << "Invalid service.user name " << CONFIG_STRING(config, "service.user") << "\n"; + } + chown(dir.c_str(), pw->pw_uid, gr->gr_gid); + } +#endif - log4cxx::PropertyConfigurator::configure(p); +#ifndef WIN32 + if (!dir.empty()) { + umask(old_cmask); + } +#endif } }