Changeset 231 for Evidence


Ignore:
Timestamp:
06/24/10 14:25:18 (15 years ago)
Author:
ogrimm
Message:
Bug fixes following previous update
Location:
Evidence
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • Evidence/DColl.cc

    r229 r231  
    5555        void RemoveService(string);
    5656        off_t FileSize(FILE *);
    57     void ConfigChanged();
    5857
    5958  public:
     
    6261};
    6362
    64 void DataHandler::ConfigChanged() {
    65   //printf("Handler called in PID %u\n", pthread_self());
    66 }
    67 
    6863//
    6964// Constructor
     
    106101  vector<string> Exclude = Tokenize(GetConfig("exclude"), " \t");
    107102  for (int i=0; i<Exclude.size(); i++) {
    108         printf("'%s'\n",Exclude[i].c_str());
    109 
    110103        int Ret = regcomp(&R, Exclude[i].c_str(), REG_EXTENDED|REG_NOSUB);
    111104        if (Ret != 0) {
     
    306299//
    307300void DataHandler::commandHandler() {
    308  return;
     301
    309302  if (getCommand() != LogCommand || LogFile == NULL) return;
    310303
     
    319312  struct tm *TM = localtime(&RawTime);
    320313
    321   fprintf(LogFile, "%2d/%2d/%4d %2d:%2d:%2d %s (ID %d): %s\n",
     314  fprintf(LogFile, "%.2d/%.2d/%4d %.2d:%.2d:%2.d %s (ID %d): %s\n",
    322315                TM->tm_mday, TM->tm_mon+1, TM->tm_year+1900,
    323316                TM->tm_hour, TM->tm_min, TM->tm_sec, getClientName(), getClientId(), Text);
    324 
    325317  fflush(LogFile);
    326318 
  • Evidence/Edd/Edd.cc

    r229 r231  
    112112  if (ServiceName != Name) return;
    113113
     114  // Check if service available
    114115  QPalette Pal = palette(); 
    115 
    116   // Check if service available
    117116  if (!SetStatus(this, Name, Time, Format, Index)) {
    118117    setText("n/a");
     
    810809
    811810  // Connect to DIM handler
    812   if (connect(this, SIGNAL(YEP(QString, int, QByteArray, QString, QString)), SLOT(Update(QString, int, QByteArray, QString, QString))) == false) {
     811  if (connect(this, SIGNAL(INT(QString, int, QByteArray, QString, QString)), SLOT(Update(QString, int, QByteArray, QString, QString))) == false) {
    813812    printf("Failed connection in EddDim()\n");
    814813  }
     
    843842  New.Name = Name;
    844843  New.ByteArray = QByteArray();
     844  New.Count = 1;
    845845  New.DIMService = new DimStampedInfo(Name.toAscii().data(), INT_MAX, NO_LINK, this);
    846   New.Count = 1;
    847846  ServiceList.append(New);
    848847
     
    936935  // Update statistics only for Dim services
    937936  if (!Name.startsWith("Edd/")) Volume += Data.size();
     937 
     938  YEP(Name, Time, Data, Format, Text); 
    938939}
    939940
     
    941942void EddDim::infoHandler() {
    942943
    943   if (!EvidenceServer::ServiceOK(getInfo())) YEP(getInfo()->getName(), -1);
     944  if (!EvidenceServer::ServiceOK(getInfo())) INT(getInfo()->getName(), -1);
    944945  else {
    945         YEP(getInfo()->getName(),
    946                 getInfo()->getTimestamp(),
    947                 QByteArray((char *) getInfo()->getData(),
    948                 getInfo()->getSize()), getInfo()->getFormat(),
    949                 QString::fromStdString(EvidenceServer::ToString(getInfo())));
     946        INT(getInfo()->getName(), getInfo()->getTimestamp(), QByteArray((char *) getInfo()->getData(),
     947                getInfo()->getSize()), getInfo()->getFormat(), QString::fromStdString(EvidenceServer::ToString(getInfo())));
    950948  }
    951949}
     
    12351233  Layout->addWidget(Command, 10, 0, 1, 4);   
    12361234
    1237   EddText *Text = new EddText("Bias/Textout", true);
     1235  EddText *Text = new EddText("Bias/ConsoleOut", true);
    12381236  Text->setFixedWidth(400);
    12391237  Layout->addWidget(Text, 11, 0, 4, 4);     
     
    16231621
    16241622
    1625 //---------------------------------------------------------------------
    16261623//**************************** Main program ***************************
    1627 //---------------------------------------------------------------------
    1628 
    16291624int main(int argc, char *argv[]) {
    16301625
  • Evidence/Edd/Edd.h

    r222 r231  
    251251  signals:
    252252    void YEP(QString, int, QByteArray = QByteArray(), QString = QString(), QString = QString());
     253    void INT(QString, int, QByteArray = QByteArray(), QString = QString(), QString = QString());
    253254};
    254255
  • Evidence/Evidence.cc

    r229 r231  
    1010    this severity, the call to Message() is guranteed not to return).
    1111  - Configuration data can be requested by GetConfig() and non-blocking by GetConfigNB().
    12   - If the configuration file changes the signal SIGUSR1 is emitted which is caught by the standard
     12  - If the configuration file changes a signal can be emitted which is caught by the standard
    1313    signal handler. The handler invokes ConfigChanged() which can be redefined by the user application.
    1414        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().
    1616  - Signal handlers to ignore common signals are installed.
    1717    These signals will then cause pause() to return which can be used
     
    4545  ConfigTimeStamp = 0;
    4646 
    47   // SIGUSR2 delivered to this thread if configuration file changes
     47  // Signal delivered to this thread if configuration file changes
    4848  ThreadID = pthread_self();
    4949
     
    7070  Unlock();
    7171
    72   if (pthread_kill(ThreadID, SIGUSR2) != 0) {
    73         ThisServer->Message(ThisServer->WARN, "Could not send signal SIGUSR2 to main thread");
     72  if (pthread_kill(ThreadID, ThisServer->ConfigSignal) != 0) {
     73        ThisServer->Message(ThisServer->WARN, "Could not send signal to main thread");
    7474  }
    7575}
     
    111111        }
    112112        else {
    113           if (Config.getSize() == 0) Result = Default;
     113          if (Config.getSize() <= 1) Result = Default;
    114114          else Result = string(Config.getString(), Config.getSize()-1); // Retrieve string safely
    115115    }
     
    143143}
    144144
    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().
    146147void EvidenceServer::Config::Lock() {
    147148
    148149  int Ret = 0;
    149150  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  }
    154157  Ret += abs(pthread_mutex_lock(&Mutex));
    155158 
     
    163166  int Ret = 0;
    164167  sigset_t Set;
    165   //printf("  Unlocking %u\n", pthread_self());
    166168
    167169  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  }
    171175
    172176  if (Ret != 0) {
     
    179183// EvidenceServer Class //
    180184//////////////////////////
     185
     186int EvidenceServer::ConfigSignal = 0;
    181187
    182188// Constructor starts server with given name
     
    195201  signal(SIGHUP, &SignalHandler);   // Terminal closed
    196202 
    197   struct sigaction S;
    198   S.sa_handler = &SignalHandler;
    199   S.sa_flags = SA_RESTART;
    200   sigaction(SIGUSR2, &S, NULL);
    201 
    202203  // Catch C++ unhandled exceptions
    203204  set_terminate(Terminate);
    204205
    205   // Configuration class (instantiate after signal handling for SIGUSR2 installed)
     206  // Configuration class (must be instantiate after signal handling installed)
    206207  ConfClass = new class Config(Name);
    207208
     
    310311}
    311312
     313// Signal emitted when configuraton file changes, signal handler calls ConfigChanged()
     314void 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
    312325// ====== Static methods ======
    313326
     
    317330  static bool Called = false;
    318331
    319   // If SIGUSR2, invoke call-back for configuraton change
    320   if (Signal == SIGUSR2) {
     332  // If signal indicates configuration change, invoke call-back
     333  if (Signal == EvidenceServer::ConfigSignal) {
    321334    ThisServer->ConfigChanged();
    322335        return;
     
    338351void EvidenceServer::Terminate() {
    339352
    340   static char Msg[STATUS_SIZE];
     353  ostringstream Msg;
    341354  static bool Terminating = false;
    342355
    343356  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());
    347360        abort();
    348361  }
     
    358371
    359372        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()) << "'";
    361374        free(Demangled);
    362375
     
    364377        try { __throw_exception_again; }
    365378        catch (exception &E) {
    366           snprintf(Msg+strlen(Msg), sizeof(Msg)-strlen(Msg), " (what(): %s)", E.what());         
     379          Msg << " (what(): " << E.what() << ")";         
    367380        }
    368381        catch (...) { }
    369382  }
    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());
    373386}
    374387
  • Evidence/Evidence.h

    r229 r231  
    1818
    1919#define NO_LINK (char *) "__&DIM&NOLINK&__" // Data if no link available
    20 #define STATUS_SIZE 1000                                        // Bytes for status service string
    2120#define EVIDENCE_REVISION "$Revision$"
    22 
    2321
    2422// Class declation of Evidence server
     
    6159        struct Message *MessageData;
    6260        class Config *ConfClass;
    63        
     61        static int ConfigSignal;                // static since accessed in signal handler
     62
    6463    static void SignalHandler(int); // static for signal()
    6564    static void Terminate();            // static for set_terminate()
     
    7776        void SendToLog(const char *, ...);
    7877        std::string GetConfig(std::string, std::string = std::string());
     78        void ActivateSignal(int);
    7979        static std::string ToString(DimInfo *);
    8080        static bool ServiceOK(DimInfo *);
Note: See TracChangeset for help on using the changeset viewer.