Changeset 255 for Evidence/Evidence.cc


Ignore:
Timestamp:
07/21/10 15:07:37 (14 years ago)
Author:
ogrimm
Message:
Added special handling of code 0 in exitHandler(), fixed recursion bug in Lock()/Unlock() by not calling Message()
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Evidence/Evidence.cc

    r253 r255  
    122122          // Return current value
    123123          Result = List[Item].Value;
    124           This->Unlock();
    125124        }
     125        This->Unlock();
    126126  }
    127127
     
    200200void EvidenceServer::exitHandler(int Code) {
    201201
    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  }
    204207}
    205208
     
    241244  }
    242245
    243   // Terminate if severity if FATAL 
    244   if (Severity == FATAL) exit(EXIT_FAILURE);
    245 
    246246  // 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.
    249247  Lock();
    250248  delete[] MessageData;
    251249  MessageData = NewMsg;
    252250  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
    257258void EvidenceServer::SendToLog(const char *Format, ...) {
    258259
     260  static char ErrorString[] = "vasprintf() failed in SendToLog()";
    259261  char *Buffer;
    260262  int Ret;
     
    271273        free (Buffer);
    272274  }
    273   else Message(ERROR, "Could not create logging text in SendToLog(), vasprintf() failed");
     275  else DimClient::sendCommandNB("DColl/Log", ErrorString);
    274276}
    275277
     
    300302
    301303
    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
    304307void EvidenceServer::Lock() {
    305308
     
    312315        Ret += abs(pthread_sigmask(SIG_BLOCK, &Set, NULL));
    313316
    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        }
    315322  }
    316323
    317324  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);
    319328  }
    320329}
     
    326335
    327336  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);
    329340  }
    330341 
     
    334345        Ret += abs(pthread_sigmask(SIG_UNBLOCK, &Set, NULL));
    335346
    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        }
    337352  }
    338353}
Note: See TracChangeset for help on using the changeset viewer.