]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- fixed logging during program termination
authorArvin Schnell <aschnell@suse.de>
Tue, 14 Aug 2012 10:05:23 +0000 (12:05 +0200)
committerArvin Schnell <aschnell@suse.de>
Tue, 14 Aug 2012 10:05:23 +0000 (12:05 +0200)
package/snapper.changes
snapper/Logger.cc

index babaa0c14c558985dfeb7f62dcae4c002daa7125..e73f59d08b3f9af42ae10010e9a650c71f3d4673 100644 (file)
@@ -1,3 +1,8 @@
+-------------------------------------------------------------------
+Tue Aug 14 12:03:50 CEST 2012 - aschnell@suse.de
+
+- fixed logging during program termination
+
 -------------------------------------------------------------------
 Wed Jul 25 10:44:38 CEST 2012 - aschnell@suse.de
 
index fbbff3d07586646fdb7738494afd7c90bea812c3..15e274b618f2038ddd88f0b2f6d91f8c99df70ce 100644 (file)
@@ -37,7 +37,10 @@ namespace snapper
     using namespace std;
 
 
-    string filename = "/var/log/snapper.log";
+    // 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");
 
     LogDo log_do = NULL;
     LogQuery log_query = NULL;
@@ -66,7 +69,7 @@ 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);
 
-       FILE* f = fopen(filename.c_str(), "a");
+       FILE* f = fopen(filename->c_str(), "a");
        if (f)
        {
            string tmp = text;
@@ -130,14 +133,16 @@ namespace snapper
     void
     initDefaultLogger()
     {
-       filename = "/var/log/snapper.log";
+       delete filename;
+       filename = new string("/var/log/snapper.log");
 
        if (geteuid())
        {
            struct passwd* pw = getpwuid(geteuid());
            if (pw)
            {
-               filename = string(pw->pw_dir) + "/.snapper.log";
+               delete filename;
+               filename = new string(string(pw->pw_dir) + "/.snapper.log");
            }
        }