Skip to content

Commit ff8de73

Browse files
authored
Merge pull request #415 from aschnell/master
- fixed logging during shutdown
2 parents 2fbeb7d + 7f293a9 commit ff8de73

File tree

10 files changed

+69
-113
lines changed

10 files changed

+69
-113
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.5
1+
0.5.6

package/snapper.changes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
-------------------------------------------------------------------
2+
Mon Jul 23 20:52:26 CEST 2018 - aschnell@suse.com
3+
4+
- fixed logging during shutdown of snapperd to avoid core dumps
5+
(bsc#1096401 and others)
6+
- version 0.5.6
7+
18
-------------------------------------------------------------------
29
Mon May 28 10:44:49 CEST 2018 - aschnell@suse.com
310

server/Client.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) [2012-2015] Novell, Inc.
3-
* Copyright (c) 2016 SUSE LLC
3+
* Copyright (c) [2016,2018] SUSE LLC
44
*
55
* All Rights Reserved.
66
*
@@ -68,11 +68,9 @@ Client::~Client()
6868
Snapshots& snapshots = snapper->getSnapshots();
6969

7070
Snapshots::iterator snap = snapshots.find(number);
71-
if (snap == snapshots.end())
72-
throw IllegalSnapshotException();
73-
74-
for (unsigned int i = 0; i < use_count; ++i)
75-
snap->umountFilesystemSnapshot(false);
71+
if (snap != snapshots.end())
72+
for (unsigned int i = 0; i < use_count; ++i)
73+
snap->umountFilesystemSnapshot(false);
7674
}
7775
}
7876

@@ -115,6 +113,7 @@ Client::delete_comparison(list<Comparison*>::iterator it)
115113
}
116114

117115
delete *it;
116+
*it = nullptr;
118117
}
119118

120119

server/MetaSnapper.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) [2012-2015] Novell, Inc.
3+
* Copyright (c) 2018 SUSE LLC
34
*
45
* All Rights Reserved.
56
*
@@ -103,6 +104,7 @@ MetaSnapper::MetaSnapper(ConfigInfo& config_info)
103104
MetaSnapper::~MetaSnapper()
104105
{
105106
delete snapper;
107+
snapper = nullptr;
106108
}
107109

108110

@@ -172,7 +174,7 @@ void
172174
MetaSnapper::unload()
173175
{
174176
delete snapper;
175-
snapper = NULL;
177+
snapper = nullptr;
176178
}
177179

178180

@@ -198,6 +200,14 @@ MetaSnappers::init()
198200
}
199201

200202

203+
void
204+
MetaSnappers::unload()
205+
{
206+
for (MetaSnapper& meta_snapper : entries)
207+
meta_snapper.unload();
208+
}
209+
210+
201211
MetaSnappers::iterator
202212
MetaSnappers::find(const string& config_name)
203213
{

server/MetaSnapper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) [2012-2015] Novell, Inc.
3+
* Copyright (c) 2018 SUSE LLC
34
*
45
* All Rights Reserved.
56
*
@@ -123,6 +124,8 @@ class MetaSnappers
123124

124125
void init();
125126

127+
void unload();
128+
126129
typedef list<MetaSnapper>::iterator iterator;
127130
typedef list<MetaSnapper>::const_iterator const_iterator;
128131

server/snapperd.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) [2012-2015] Novell, Inc.
3+
* Copyright (c) 2018 SUSE LLC
34
*
45
* All Rights Reserved.
56
*
@@ -286,5 +287,7 @@ main(int argc, char** argv)
286287

287288
y2mil("Exiting");
288289

290+
meta_snappers.unload();
291+
289292
return 0;
290293
}

snapper/Log.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ namespace snapper
6464
{
6565
callLogDo(level, *component, file, line, func, stream->str());
6666
delete stream;
67+
stream = nullptr;
6768
}
6869

6970
}

snapper/Logger.cc

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) [2004-2013] Novell, Inc.
3+
* Copyright (c) 2018 SUSE LLC
34
*
45
* All Rights Reserved.
56
*
@@ -32,15 +33,33 @@
3233
#include "snapper/AppUtil.h"
3334

3435

36+
#define LOG_FILENAME "/var/log/snapper.log"
37+
38+
3539
namespace snapper
3640
{
3741
using namespace std;
3842

3943

40-
// Use a pointer to avoid a global destructor. Otherwise the Snapper
41-
// destructor in Factory.cc can be called after when logging does not work
42-
// anymore. TODO: nicer solution.
43-
string* filename = new string("/var/log/snapper.log");
44+
namespace
45+
{
46+
47+
struct LoggerData
48+
{
49+
LoggerData() : filename(LOG_FILENAME), mutex() {}
50+
51+
string filename;
52+
boost::mutex mutex;
53+
};
54+
55+
56+
// Use pointer to avoid a global destructor. Otherwise other global
57+
// destructors using logging can cause errors.
58+
59+
LoggerData* logger_data = new LoggerData();
60+
61+
}
62+
4463

4564
LogDo log_do = NULL;
4665
LogQuery log_query = NULL;
@@ -69,11 +88,9 @@ namespace snapper
6988
string prefix = sformat("%s %s libsnapper(%d) %s(%s):%d", datetime(time(0), false, true).c_str(),
7089
ln[level], getpid(), file, func, line);
7190

72-
static boost::mutex mutex;
73-
74-
boost::lock_guard<boost::mutex> lock(mutex);
91+
boost::lock_guard<boost::mutex> lock(logger_data->mutex);
7592

76-
FILE* f = fopen(filename->c_str(), "ae");
93+
FILE* f = fopen(logger_data->filename.c_str(), "ae");
7794
if (f)
7895
{
7996
string tmp = text;
@@ -137,8 +154,7 @@ namespace snapper
137154
void
138155
initDefaultLogger()
139156
{
140-
delete filename;
141-
filename = new string("/var/log/snapper.log");
157+
logger_data->filename = LOG_FILENAME;
142158

143159
if (geteuid())
144160
{
@@ -152,8 +168,7 @@ namespace snapper
152168
{
153169
memset(pwd.pw_passwd, 0, strlen(pwd.pw_passwd));
154170

155-
delete filename;
156-
filename = new string(string(pwd.pw_dir) + "/.snapper.log");
171+
logger_data->filename = string(pwd.pw_dir) + "/.snapper.log";
157172
}
158173
}
159174

snapper/Snapper.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) [2011-2015] Novell, Inc.
3-
* Copyright (c) 2016 SUSE LLC
3+
* Copyright (c) [2016,2018] SUSE LLC
44
*
55
* All Rights Reserved.
66
*
@@ -147,7 +147,10 @@ namespace snapper
147147
}
148148

149149
delete filesystem;
150+
filesystem = nullptr;
151+
150152
delete config_info;
153+
config_info = nullptr;
151154
}
152155

153156

snapper/SnapperTmpl.h

Lines changed: 7 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#ifndef SNAPPER_SNAPPER_TMPL_H
2424
#define SNAPPER_SNAPPER_TMPL_H
2525

26-
#include <functional>
26+
2727
#include <ostream>
2828
#include <fstream>
2929
#include <sstream>
@@ -32,6 +32,7 @@
3232

3333
#include "snapper/AppUtil.h"
3434

35+
3536
namespace snapper
3637
{
3738
using std::string;
@@ -47,6 +48,7 @@ namespace snapper
4748
return num_str.str();
4849
}
4950

51+
5052
template<class Num> string hexString(Num number)
5153
{
5254
static_assert(std::is_integral<Num>::value, "not integral");
@@ -57,13 +59,15 @@ namespace snapper
5759
return num_str.str();
5860
}
5961

62+
6063
template<class Value> void operator>>(const string& d, Value& v)
6164
{
6265
std::istringstream Data(d);
6366
classic(Data);
6467
Data >> v;
6568
}
6669

70+
6771
template<class Value> std::ostream& operator<<( std::ostream& s, const std::list<Value>& l )
6872
{
6973
s << "<";
@@ -77,12 +81,14 @@ namespace snapper
7781
return( s );
7882
}
7983

84+
8085
template<class F, class S> std::ostream& operator<<( std::ostream& s, const std::pair<F,S>& p )
8186
{
8287
s << "[" << p.first << ":" << p.second << "]";
8388
return( s );
8489
}
8590

91+
8692
template<class Key, class Value> std::ostream& operator<<( std::ostream& s, const std::map<Key,Value>& m )
8793
{
8894
s << "<";
@@ -97,76 +103,6 @@ namespace snapper
97103
}
98104

99105

100-
template <typename Type>
101-
void logDiff(std::ostream& log, const char* text, const Type& lhs, const Type& rhs)
102-
{
103-
static_assert(!std::is_enum<Type>::value, "is enum");
104-
105-
if (lhs != rhs)
106-
log << " " << text << ":" << lhs << "-->" << rhs;
107-
}
108-
109-
template <typename Type>
110-
void logDiffHex(std::ostream& log, const char* text, const Type& lhs, const Type& rhs)
111-
{
112-
static_assert(std::is_integral<Type>::value, "not integral");
113-
114-
if (lhs != rhs)
115-
log << " " << text << ":" << std::hex << lhs << "-->" << rhs << std::dec;
116-
}
117-
118-
template <typename Type>
119-
void logDiffEnum(std::ostream& log, const char* text, const Type& lhs, const Type& rhs)
120-
{
121-
static_assert(std::is_enum<Type>::value, "not enum");
122-
123-
if (lhs != rhs)
124-
log << " " << text << ":" << toString(lhs) << "-->" << toString(rhs);
125-
}
126-
127-
inline
128-
void logDiff(std::ostream& log, const char* text, bool lhs, bool rhs)
129-
{
130-
if (lhs != rhs)
131-
{
132-
if (rhs)
133-
log << " -->" << text;
134-
else
135-
log << " " << text << "-->";
136-
}
137-
}
138-
139-
140-
template<class Type>
141-
struct deref_less : public std::binary_function<const Type*, const Type*, bool>
142-
{
143-
bool operator()(const Type* x, const Type* y) const { return *x < *y; }
144-
};
145-
146-
147-
template<class Type>
148-
struct deref_equal_to : public std::binary_function<const Type*, const Type*, bool>
149-
{
150-
bool operator()(const Type* x, const Type* y) const { return *x == *y; }
151-
};
152-
153-
154-
template <class Type>
155-
void pointerIntoSortedList(list<Type*>& l, Type* e)
156-
{
157-
l.insert(lower_bound(l.begin(), l.end(), e, deref_less<Type>()), e);
158-
}
159-
160-
161-
template <class Type>
162-
void clearPointerList(list<Type*>& l)
163-
{
164-
for (typename list<Type*>::iterator i = l.begin(); i != l.end(); ++i)
165-
delete *i;
166-
l.clear();
167-
}
168-
169-
170106
template <typename ListType, typename Type>
171107
bool contains(const ListType& l, const Type& value)
172108
{
@@ -181,27 +117,6 @@ namespace snapper
181117
}
182118

183119

184-
template<typename Map, typename Key, typename Value>
185-
typename Map::iterator mapInsertOrReplace(Map& m, const Key& k, const Value& v)
186-
{
187-
typename Map::iterator pos = m.lower_bound(k);
188-
if (pos != m.end() && !typename Map::key_compare()(k, pos->first))
189-
pos->second = v;
190-
else
191-
pos = m.insert(pos, typename Map::value_type(k, v));
192-
return pos;
193-
}
194-
195-
template<typename List, typename Value>
196-
typename List::const_iterator addIfNotThere(List& l, const Value& v)
197-
{
198-
typename List::const_iterator pos = find( l.begin(), l.end(), v );
199-
if (pos == l.end() )
200-
pos = l.insert(l.end(), v);
201-
return pos;
202-
}
203-
204-
205120
template <class T, unsigned int sz>
206121
inline unsigned int lengthof(T (&)[sz]) { return sz; }
207122

0 commit comments

Comments
 (0)