From: Arvin Schnell Date: Mon, 23 Jul 2018 18:56:32 +0000 (+0200) Subject: - fixed logging during shutdown X-Git-Tag: v0.5.6^2~6 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=4fef854f4f3224afa438f5fdb681c005bc2d7871;p=thirdparty%2Fsnapper.git - fixed logging during shutdown --- diff --git a/VERSION b/VERSION index d1d899fa..b49b2533 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.5 +0.5.6 diff --git a/package/snapper.changes b/package/snapper.changes index 808c45a5..336c2e44 100644 --- a/package/snapper.changes +++ b/package/snapper.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Mon Jul 23 20:52:26 CEST 2018 - aschnell@suse.com + +- fixed logging during shutdown of snapperd to avoid core dumps + (bsc#1096401 and others) +- version 0.5.6 + ------------------------------------------------------------------- Mon May 28 10:44:49 CEST 2018 - aschnell@suse.com diff --git a/snapper/Logger.cc b/snapper/Logger.cc index 817a3cca..71d72af4 100644 --- a/snapper/Logger.cc +++ b/snapper/Logger.cc @@ -1,5 +1,6 @@ /* * Copyright (c) [2004-2013] Novell, Inc. + * Copyright (c) 2018 SUSE LLC * * All Rights Reserved. * @@ -37,10 +38,25 @@ namespace snapper using namespace std; - // Use a pointer to avoid a global destructor. Otherwise the Snapper - // destructor in Factory.cc can be called after when logging does not work - // anymore. TODO: nicer solution. - string* filename = new string("/var/log/snapper.log"); + namespace + { + + struct LoggerData + { + LoggerData() : filename("/var/log/snapper.log"), mutex() {} + + string filename; + boost::mutex mutex; + }; + + + // Use pointer to avoid a global destructor. Otherwise other global + // destructors using logging can cause errors. + + LoggerData* logger_data = new LoggerData(); + + } + LogDo log_do = NULL; LogQuery log_query = NULL; @@ -69,11 +85,9 @@ namespace snapper string prefix = sformat("%s %s libsnapper(%d) %s(%s):%d", datetime(time(0), false, true).c_str(), ln[level], getpid(), file, func, line); - static boost::mutex mutex; - - boost::lock_guard lock(mutex); + boost::lock_guard lock(logger_data->mutex); - FILE* f = fopen(filename->c_str(), "ae"); + FILE* f = fopen(logger_data->filename.c_str(), "ae"); if (f) { string tmp = text; @@ -137,8 +151,7 @@ namespace snapper void initDefaultLogger() { - delete filename; - filename = new string("/var/log/snapper.log"); + logger_data->filename = "/var/log/snapper.log"; if (geteuid()) { @@ -152,8 +165,7 @@ namespace snapper { memset(pwd.pw_passwd, 0, strlen(pwd.pw_passwd)); - delete filename; - filename = new string(string(pwd.pw_dir) + "/.snapper.log"); + logger_data->filename = string(pwd.pw_dir) + "/.snapper.log"; } }