- Timestamp:
- 02/09/10 06:49:45 (15 years ago)
- Location:
- Evidence
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Evidence/Evidence.cc
r164 r165 15 15 - The static method ToString() converts the contents of a 16 16 DIMInfo service into text 17 17 - A terminate-handler is installed for catching unhandled C++ exceptions. 18 18 19 All memory allocated by the non-static methods will be freed by the 19 20 class destructor. 20 21 21 Oliver Grimm, December200922 Oliver Grimm, February 2009 22 23 23 24 \********************************************************************/ … … 51 52 52 53 // Start server 53 static char Init[] = "Server started (" EVIDENCE_REVISION " Compiled "__DATE__ __TIME__ ")"; 54 Status = new DimService((string(Name) + "/Status").c_str(), (char *) "C", Init, sizeof(Init)); 54 string Rev(EVIDENCE_REVISION); 55 Rev = Rev.substr(1, Rev.size()-3); 56 if (asprintf(&InitMsg, "Server started (%s, compiled %s)", Rev.c_str(),__TIMESTAMP__) == -1) InitMsg = NULL; 57 58 Status = new DimService((string(Name) + "/Status").c_str(), (char *) "C", InitMsg, strlen(InitMsg)+1); 55 59 56 60 start(Name); … … 61 65 EvidenceServer::~EvidenceServer() { 62 66 67 free(InitMsg); 63 68 State(INFO, "Server stopped"); 64 69 … … 182 187 } 183 188 184 // C++ exception handler 189 // C++ exception handler (derived from gcc __verbose_terminate_handler()) 185 190 void EvidenceServer::Terminate() { 186 191 187 string Msg = string(ThisServer->Status->getName()) + ": Caught unhandled exception"; 188 189 printf("%s\n", Msg.c_str()); 190 DimClient::sendCommand("DColl/Log", Msg.c_str()); 191 192 abort(); 192 static char Msg[STATUS_SIZE]; 193 static bool Terminating = false; 194 195 if (Terminating) { 196 snprintf(Msg, sizeof(Msg), "%s: Terminate() called recursively, calling abort()", ThisServer->Status->getName()); 197 printf("%s\n", Msg); 198 DimClient::sendCommandNB("DColl/Log", Msg); 199 abort(); 200 } 201 else { 202 Terminating = true; 203 204 // Make sure there was an exception; terminate is also called for an 205 // attempt to rethrow when there is no suitable exception. 206 type_info *Type = abi::__cxa_current_exception_type(); 207 if (Type != NULL) { 208 int Status = -1; 209 char *Demangled = NULL; 210 211 Demangled = abi::__cxa_demangle(Type->name(), 0, 0, &Status); 212 snprintf(Msg, sizeof(Msg), "%s: Terminate() called after throwing an instance of '%s'", ThisServer->Status->getName(), Status==0 ? Demangled : Type->name()); 213 free(Demangled); 214 215 // If exception derived from std::exception, more information. 216 try { __throw_exception_again; } 217 catch (exception &E) { 218 snprintf(Msg+strlen(Msg), sizeof(Msg)-strlen(Msg), " (what(): %s)", E.what()); 219 } 220 catch (...) { } 221 } 222 else snprintf(Msg, sizeof(Msg), "%s: Terminate() called without an active exception", ThisServer->Status->getName()); 223 } 224 225 ThisServer->State(FATAL, Msg); 193 226 } 194 227 -
Evidence/Evidence.h
r164 r165 6 6 #include <string> 7 7 #include <errno.h> 8 #include <vector> 8 9 #include <exception> 9 #include < vector>10 10 #include <cxxabi.h> 11 11 12 #include "dis.hxx" 12 13 #include "dic.hxx" … … 28 29 29 30 DimService *Status; 31 char *InitMsg; 30 32 31 33 static void SignalHandler(int); // static for signal()
Note:
See TracChangeset
for help on using the changeset viewer.