Changeset 187 for Evidence/Evidence.cc


Ignore:
Timestamp:
03/29/10 09:28:17 (15 years ago)
Author:
ogrimm
Message:
Updates to signal handling
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Evidence/Evidence.cc

    r178 r187  
    4747  signal(SIGINT, &SignalHandler);   // CTRL-C
    4848  signal(SIGHUP, &SignalHandler);   // Terminal closed
    49  
     49
    5050  // Catch C++ unhandled exceptions
    5151  set_terminate(Terminate);
     
    5757  string Rev(EVIDENCE_REVISION);
    5858  Rev = Rev.substr(1, Rev.size()-3);
    59   if (asprintf(&InitMsg, "Server started (%s, compiled %s %s)", Rev.c_str(),__DATE__, __TIME__) == -1) InitMsg = NULL;
     59  snprintf(InitMsg, sizeof(InitMsg), "Server started (%s, compiled %s %s)", Rev.c_str(),__DATE__, __TIME__);
    6060 
    6161  Status = new DimService((ServerName+"/Status").c_str(), (char *) "C", InitMsg, strlen(InitMsg)+1);
     
    6868EvidenceServer::~EvidenceServer() {
    6969
    70   free(InitMsg);
    7170  State(INFO, "Server stopped");
    7271 
     
    7978// DIM exit handler
    8079void EvidenceServer::exitHandler(int Code) {
     80
    8181  State(INFO, "Exit handler called (DIM exit code %d)", Code);
    8282  exit(EXIT_SUCCESS);
     
    181181
    182182// Signal handler (causes pause() and other syscalls to return)
    183 void EvidenceServer::SignalHandler(int) {
    184 
    185   ThisServer->ExitRequest = true;
     183void EvidenceServer::SignalHandler(int Signal) {
     184
     185  static bool Called = false;
     186
     187  if (!Called) {
     188        Called = true;
     189        ThisServer->ExitRequest = true;
     190        return;
     191  }
     192
     193  // If invoked twice, call exit()
     194  ThisServer->State(ThisServer->WARN, "Signal handler called again, invoking exit() (signal %d)", Signal);
     195  exit(EXIT_FAILURE);
    186196}
    187197
Note: See TracChangeset for help on using the changeset viewer.