Changeset 231 for Evidence/Evidence.cc
- Timestamp:
- 06/24/10 14:25:18 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Evidence/Evidence.cc
r229 r231 10 10 this severity, the call to Message() is guranteed not to return). 11 11 - Configuration data can be requested by GetConfig() and non-blocking by GetConfigNB(). 12 - If the configuration file changes the signal SIGUSR1 isemitted which is caught by the standard12 - If the configuration file changes a signal can be emitted which is caught by the standard 13 13 signal handler. The handler invokes ConfigChanged() which can be redefined by the user application. 14 14 The signal is delivered only to the main thread (where the constructor is executed) and thus 15 blocking rpc can be made from it. 15 blocking rpc can be made from it. The signal is set using ActivateSignal(). 16 16 - Signal handlers to ignore common signals are installed. 17 17 These signals will then cause pause() to return which can be used … … 45 45 ConfigTimeStamp = 0; 46 46 47 // S IGUSR2delivered to this thread if configuration file changes47 // Signal delivered to this thread if configuration file changes 48 48 ThreadID = pthread_self(); 49 49 … … 70 70 Unlock(); 71 71 72 if (pthread_kill(ThreadID, SIGUSR2) != 0) {73 ThisServer->Message(ThisServer->WARN, "Could not send signal SIGUSR2to main thread");72 if (pthread_kill(ThreadID, ThisServer->ConfigSignal) != 0) { 73 ThisServer->Message(ThisServer->WARN, "Could not send signal to main thread"); 74 74 } 75 75 } … … 111 111 } 112 112 else { 113 if (Config.getSize() == 0) Result = Default;113 if (Config.getSize() <= 1) Result = Default; 114 114 else Result = string(Config.getString(), Config.getSize()-1); // Retrieve string safely 115 115 } … … 143 143 } 144 144 145 // Locking and unlocking for list access. Signal SIGUSR2 is also blocked. 145 // Locking and unlocking for list access 146 // Signal blocked before locking to avaoid dead-lock by calling GetConfig() from ConfigChanged(). 146 147 void EvidenceServer::Config::Lock() { 147 148 148 149 int Ret = 0; 149 150 sigset_t Set; 150 //printf("Locking %u\n", pthread_self()); 151 Ret += abs(sigemptyset(&Set)); 152 Ret += abs(sigaddset(&Set, SIGUSR2)); 153 Ret += abs(pthread_sigmask(SIG_BLOCK, &Set, NULL)); 151 152 if (ThisServer->ConfigSignal != 0) { 153 Ret += abs(sigemptyset(&Set)); 154 Ret += abs(sigaddset(&Set, ThisServer->ConfigSignal)); 155 Ret += abs(pthread_sigmask(SIG_BLOCK, &Set, NULL)); 156 } 154 157 Ret += abs(pthread_mutex_lock(&Mutex)); 155 158 … … 163 166 int Ret = 0; 164 167 sigset_t Set; 165 //printf(" Unlocking %u\n", pthread_self());166 168 167 169 Ret += abs(pthread_mutex_unlock(&Mutex)); 168 Ret += abs(sigemptyset(&Set)); 169 Ret += abs(sigaddset(&Set, SIGUSR2)); 170 Ret += abs(pthread_sigmask(SIG_UNBLOCK, &Set, NULL)); 170 if (ThisServer->ConfigSignal != 0) { 171 Ret += abs(sigemptyset(&Set)); 172 Ret += abs(sigaddset(&Set, ThisServer->ConfigSignal)); 173 Ret += abs(pthread_sigmask(SIG_UNBLOCK, &Set, NULL)); 174 } 171 175 172 176 if (Ret != 0) { … … 179 183 // EvidenceServer Class // 180 184 ////////////////////////// 185 186 int EvidenceServer::ConfigSignal = 0; 181 187 182 188 // Constructor starts server with given name … … 195 201 signal(SIGHUP, &SignalHandler); // Terminal closed 196 202 197 struct sigaction S;198 S.sa_handler = &SignalHandler;199 S.sa_flags = SA_RESTART;200 sigaction(SIGUSR2, &S, NULL);201 202 203 // Catch C++ unhandled exceptions 203 204 set_terminate(Terminate); 204 205 205 // Configuration class ( instantiate after signal handling for SIGUSR2installed)206 // Configuration class (must be instantiate after signal handling installed) 206 207 ConfClass = new class Config(Name); 207 208 … … 310 311 } 311 312 313 // Signal emitted when configuraton file changes, signal handler calls ConfigChanged() 314 void EvidenceServer::ActivateSignal(int Signal) { 315 316 struct sigaction S; 317 318 ConfigSignal = Signal; 319 S.sa_handler = &SignalHandler; 320 S.sa_flags = SA_RESTART; 321 sigaction(Signal, &S, NULL); 322 } 323 324 312 325 // ====== Static methods ====== 313 326 … … 317 330 static bool Called = false; 318 331 319 // If SIGUSR2, invoke call-back for configuraton change320 if (Signal == SIGUSR2) {332 // If signal indicates configuration change, invoke call-back 333 if (Signal == EvidenceServer::ConfigSignal) { 321 334 ThisServer->ConfigChanged(); 322 335 return; … … 338 351 void EvidenceServer::Terminate() { 339 352 340 static char Msg[STATUS_SIZE];353 ostringstream Msg; 341 354 static bool Terminating = false; 342 355 343 356 if (Terminating) { 344 snprintf(Msg, sizeof(Msg), "%s: Terminate() called recursively, calling abort()", ThisServer->MessageService->getName());345 printf("%s\n", Msg );346 DimClient::sendCommandNB("DColl/Log", Msg);357 Msg << ThisServer->Name << ": Terminate() called recursively, calling abort()"; 358 printf("%s\n", Msg.str().c_str()); 359 ThisServer->SendToLog(Msg.str().c_str()); 347 360 abort(); 348 361 } … … 358 371 359 372 Demangled = abi::__cxa_demangle(Type->name(), 0, 0, &Status); 360 snprintf(Msg, sizeof(Msg), "Terminate() called after throwing an instance of '%s'", Status==0 ? Demangled : Type->name());373 Msg << "Terminate() called after throwing an instance of '" << (Status==0 ? Demangled : Type->name()) << "'"; 361 374 free(Demangled); 362 375 … … 364 377 try { __throw_exception_again; } 365 378 catch (exception &E) { 366 snprintf(Msg+strlen(Msg), sizeof(Msg)-strlen(Msg), " (what(): %s)", E.what());379 Msg << " (what(): " << E.what() << ")"; 367 380 } 368 381 catch (...) { } 369 382 } 370 else snprintf(Msg, sizeof(Msg), "Terminate() called without an active exception");371 372 ThisServer->Message(FATAL, Msg );383 else Msg << "Terminate() called without an active exception"; 384 385 ThisServer->Message(FATAL, Msg.str().c_str()); 373 386 } 374 387
Note:
See TracChangeset
for help on using the changeset viewer.