- Timestamp:
- 06/24/10 14:25:18 (15 years ago)
- Location:
- Evidence
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
Evidence/DColl.cc
r229 r231 55 55 void RemoveService(string); 56 56 off_t FileSize(FILE *); 57 void ConfigChanged();58 57 59 58 public: … … 62 61 }; 63 62 64 void DataHandler::ConfigChanged() {65 //printf("Handler called in PID %u\n", pthread_self());66 }67 68 63 // 69 64 // Constructor … … 106 101 vector<string> Exclude = Tokenize(GetConfig("exclude"), " \t"); 107 102 for (int i=0; i<Exclude.size(); i++) { 108 printf("'%s'\n",Exclude[i].c_str());109 110 103 int Ret = regcomp(&R, Exclude[i].c_str(), REG_EXTENDED|REG_NOSUB); 111 104 if (Ret != 0) { … … 306 299 // 307 300 void DataHandler::commandHandler() { 308 return; 301 309 302 if (getCommand() != LogCommand || LogFile == NULL) return; 310 303 … … 319 312 struct tm *TM = localtime(&RawTime); 320 313 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", 322 315 TM->tm_mday, TM->tm_mon+1, TM->tm_year+1900, 323 316 TM->tm_hour, TM->tm_min, TM->tm_sec, getClientName(), getClientId(), Text); 324 325 317 fflush(LogFile); 326 318 -
Evidence/Edd/Edd.cc
r229 r231 112 112 if (ServiceName != Name) return; 113 113 114 // Check if service available 114 115 QPalette Pal = palette(); 115 116 // Check if service available117 116 if (!SetStatus(this, Name, Time, Format, Index)) { 118 117 setText("n/a"); … … 810 809 811 810 // 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) { 813 812 printf("Failed connection in EddDim()\n"); 814 813 } … … 843 842 New.Name = Name; 844 843 New.ByteArray = QByteArray(); 844 New.Count = 1; 845 845 New.DIMService = new DimStampedInfo(Name.toAscii().data(), INT_MAX, NO_LINK, this); 846 New.Count = 1;847 846 ServiceList.append(New); 848 847 … … 936 935 // Update statistics only for Dim services 937 936 if (!Name.startsWith("Edd/")) Volume += Data.size(); 937 938 YEP(Name, Time, Data, Format, Text); 938 939 } 939 940 … … 941 942 void EddDim::infoHandler() { 942 943 943 if (!EvidenceServer::ServiceOK(getInfo())) YEP(getInfo()->getName(), -1);944 if (!EvidenceServer::ServiceOK(getInfo())) INT(getInfo()->getName(), -1); 944 945 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()))); 950 948 } 951 949 } … … 1235 1233 Layout->addWidget(Command, 10, 0, 1, 4); 1236 1234 1237 EddText *Text = new EddText("Bias/ Textout", true);1235 EddText *Text = new EddText("Bias/ConsoleOut", true); 1238 1236 Text->setFixedWidth(400); 1239 1237 Layout->addWidget(Text, 11, 0, 4, 4); … … 1623 1621 1624 1622 1625 //---------------------------------------------------------------------1626 1623 //**************************** Main program *************************** 1627 //---------------------------------------------------------------------1628 1629 1624 int main(int argc, char *argv[]) { 1630 1625 -
Evidence/Edd/Edd.h
r222 r231 251 251 signals: 252 252 void YEP(QString, int, QByteArray = QByteArray(), QString = QString(), QString = QString()); 253 void INT(QString, int, QByteArray = QByteArray(), QString = QString(), QString = QString()); 253 254 }; 254 255 -
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 -
Evidence/Evidence.h
r229 r231 18 18 19 19 #define NO_LINK (char *) "__&DIM&NOLINK&__" // Data if no link available 20 #define STATUS_SIZE 1000 // Bytes for status service string21 20 #define EVIDENCE_REVISION "$Revision$" 22 23 21 24 22 // Class declation of Evidence server … … 61 59 struct Message *MessageData; 62 60 class Config *ConfClass; 63 61 static int ConfigSignal; // static since accessed in signal handler 62 64 63 static void SignalHandler(int); // static for signal() 65 64 static void Terminate(); // static for set_terminate() … … 77 76 void SendToLog(const char *, ...); 78 77 std::string GetConfig(std::string, std::string = std::string()); 78 void ActivateSignal(int); 79 79 static std::string ToString(DimInfo *); 80 80 static bool ServiceOK(DimInfo *);
Note:
See TracChangeset
for help on using the changeset viewer.