Changeset 255 for Evidence/Evidence.cc
- Timestamp:
- 07/21/10 15:07:37 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Evidence/Evidence.cc
r253 r255 122 122 // Return current value 123 123 Result = List[Item].Value; 124 This->Unlock();125 124 } 125 This->Unlock(); 126 126 } 127 127 … … 200 200 void EvidenceServer::exitHandler(int Code) { 201 201 202 Message(INFO, "Exit handler called (DIM exit code %d)", Code); 203 exit(EXIT_SUCCESS); 202 if (Code == 0) Message(INFO, "Message cleared by %s (ID %d)", getClientName(), getClientId()); 203 else { 204 Message(INFO, "Exit handler called (DIM exit code %d)", Code); 205 exit(EXIT_SUCCESS); 206 } 204 207 } 205 208 … … 241 244 } 242 245 243 // Terminate if severity if FATAL244 if (Severity == FATAL) exit(EXIT_FAILURE);245 246 246 // Delete old message 247 // Note that Lock()/Unlock() might fail with a FATAL message. To avoid an infinite loop,248 // check for FATAL severity is done before here.249 247 Lock(); 250 248 delete[] MessageData; 251 249 MessageData = NewMsg; 252 250 Unlock(); 253 } 254 255 256 // Set to central logging server with non-blocking command (may be used in DIM handler) 251 252 // Terminate if severity if FATAL 253 if (Severity == FATAL) exit(EXIT_FAILURE); 254 } 255 256 257 // Send to central logging server with non-blocking command 257 258 void EvidenceServer::SendToLog(const char *Format, ...) { 258 259 260 static char ErrorString[] = "vasprintf() failed in SendToLog()"; 259 261 char *Buffer; 260 262 int Ret; … … 271 273 free (Buffer); 272 274 } 273 else Message(ERROR, "Could not create logging text in SendToLog(), vasprintf() failed");275 else DimClient::sendCommandNB("DColl/Log", ErrorString); 274 276 } 275 277 … … 300 302 301 303 302 // Locking and unlocking for list access 303 // Signal blocked before locking to avoid dead-lock by calling GetConfig() from ConfigChanged(). 304 // Locking and unlocking functions. 305 // Signal blocked before locking (pthread_mutex_lock() not asynch-signal safe). 306 // Message() is not used to avoid infinite recursion 304 307 void EvidenceServer::Lock() { 305 308 … … 312 315 Ret += abs(pthread_sigmask(SIG_BLOCK, &Set, NULL)); 313 316 314 if (Ret != 0) Message(FATAL, "Signal masking failed in Lock()"); 317 if (Ret != 0) { 318 printf("Signal masking failed in Lock()"); 319 SendToLog("Signal masking failed in Lock()"); 320 exit(EXIT_FAILURE); 321 } 315 322 } 316 323 317 324 if ((Ret = pthread_mutex_lock(&Mutex)) != 0) { 318 Message(FATAL, "pthread_mutex_lock() failed in Lock() (%s)", strerror(Ret)); 325 printf("pthread_mutex_lock() failed in Lock() (%s)", strerror(Ret)); 326 SendToLog("pthread_mutex_lock() failed in Lock() (%s)", strerror(Ret)); 327 exit(EXIT_FAILURE); 319 328 } 320 329 } … … 326 335 327 336 if ((Ret = pthread_mutex_unlock(&Mutex)) != 0) { 328 Message(FATAL, "pthread_mutex_unlock() failed in Unlock() (%s)", strerror(Ret)); 337 printf("pthread_mutex_unlock() failed in Unlock() (%s)", strerror(Ret)); 338 SendToLog("pthread_mutex_unlock() failed in Unlock() (%s)", strerror(Ret)); 339 exit(EXIT_FAILURE); 329 340 } 330 341 … … 334 345 Ret += abs(pthread_sigmask(SIG_UNBLOCK, &Set, NULL)); 335 346 336 if (Ret != 0) Message(FATAL, "Signal unmasking failed in Unlock()"); 347 if (Ret != 0) { 348 printf("Signal unmasking failed in Unlock()"); 349 SendToLog("Signal unmasking failed in Unlock()"); 350 exit(EXIT_FAILURE); 351 } 337 352 } 338 353 }
Note:
See TracChangeset
for help on using the changeset viewer.