exit(1);
}
- declareStats();
+ try {
+ declareStats();
+ }
+ catch(PDNSException &PE) {
+ g_log<<Logger::Error<<"Exiting because: "<<PE.reason<<endl;
+ exit(1);
+ }
S.blacklist("special-memory-usage");
DLOG(g_log<<Logger::Warning<<"Verbose logging in effect"<<endl);
StatBag::StatBag()
{
d_doRings=false;
+ d_allowRedeclare=false;
}
void StatBag::exists(const string &key)
void StatBag::declare(const string &key, const string &descrip, StatType statType)
{
if(d_stats.count(key)) {
- *d_stats[key] = 0;
- return;
+ if (d_allowRedeclare) {
+ *d_stats[key] = 0;
+ return;
+ }
+ else {
+ throw PDNSException("Attempt to re-declare statbag '"+key+"'");
+ }
}
auto i=make_unique<AtomicCounter>(0);
void StatBag::declare(const string &key, const string &descrip, StatBag::func_t func, StatType statType)
{
+ if(d_funcstats.count(key) && !d_allowRedeclare) {
+ throw PDNSException("Attempt to re-declare func statbag '"+key+"'");
+ }
+
d_funcstats[key]=func;
d_keyDescrips[key]=descrip;
d_statTypes[key]=statType;
typedef map<string, func_t> funcstats_t;
funcstats_t d_funcstats;
bool d_doRings;
+
std::set<string> d_blacklist;
void registerRingStats(const string& name);
string getValueStr(const string &key); //!< read a value behind a key, and return it as a string
string getValueStrZero(const string &key); //!< read a value behind a key, and return it as a string, and zero afterwards
void blacklist(const string &str);
+
+ bool d_allowRedeclare; // only set this true during tests, never in production code
};
inline void StatBag::deposit(const string &key, int value)
// entry point:
int main(int argc, char* argv[])
{
+ S.d_allowRedeclare = true;
return boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
}