Changeset 213 for Evidence/DColl.cc
- Timestamp:
- 05/25/10 08:54:18 (16 years ago)
- File:
-
- 1 edited
-
Evidence/DColl.cc (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Evidence/DColl.cc
r212 r213 80 80 void AddService(string); 81 81 void RemoveService(string); 82 float FileSize(FILE *);82 off_t FileSize(FILE *); 83 83 FILE *OpenHistFile(string, const char *); 84 84 … … 124 124 DataSizeService = new DimService(SERVER_NAME "/DataSizekB", DataSizekB); 125 125 126 LogSizekB = FileSize(LogFile) ;126 LogSizekB = FileSize(LogFile)/1024.0; 127 127 LogSizeService = new DimService(SERVER_NAME "/LogSizekB", LogSizekB); 128 128 … … 220 220 // ====== Part A: Handle service subscriptions === 221 221 // 222 // Services are added here, removal only in constructor. 222 223 223 224 // If service is DIS_DNS/SERVER_LIST, subscribe to all SERVICE_LIST services … … 225 226 char *Token = strtok(Info->getString(), "+-!@"); 226 227 while (Token != NULL) { 227 if (*Info->getString()=='+') AddService(string(Token)+"/SERVICE_LIST");228 AddService(string(Token)+"/SERVICE_LIST"); // 'add' also for '-' and '!' 228 229 Token = strtok(NULL, "|"); // Skip server IP address 229 230 Token = strtok(NULL, "@"); … … 240 241 char *Type = strtok(NULL, "\n"); 241 242 if (Type == NULL) return; // for safety, should not happen 242 if (strstr(Type, "|CMD")==NULL && strstr(Type, "|RPC")==NULL) { 243 // Add or remove service 244 if (*Info->getString()=='+') AddService(Name); 245 } 243 if (strstr(Type, "|CMD")==NULL && strstr(Type, "|RPC")==NULL) AddService(Name); // 'add' also for '-' and '!' 246 244 Name = strtok(NULL, "|"); 247 245 } … … 346 344 fflush(DataFile); // not continuously to reduce load 347 345 348 DataSizekB = FileSize(DataFile) ;346 DataSizekB = FileSize(DataFile)/1024.0; 349 347 DataSizeService->updateService(); 350 348 DataSizeLastUpdate = time(NULL); … … 454 452 // Update logfile size service 455 453 if (time(NULL) - LogSizeLastUpdate > SizeUpdateDelay) { 456 LogSizekB = FileSize(LogFile) ;454 LogSizekB = FileSize(LogFile)/1024.0; 457 455 LogSizeService->updateService(); 458 456 LogSizeLastUpdate = time(NULL); … … 473 471 } 474 472 } 475 476 // Default response 477 setData(NULL, 0); 473 474 // Try to open history file if not found in memory 475 FILE *File = OpenHistFile(getString(), "rb"); 476 if (File == NULL) { 477 setData(NULL, 0); 478 return; 479 } 480 481 // Read history file 482 off_t Size = FileSize(File); 483 if (Size != -1) { 484 char *Buffer = new char [Size-sizeof(int)]; 485 fseek(File, sizeof(int), SEEK_SET); 486 fread(Buffer, sizeof(char), Size-sizeof(int), File); 487 if (ferror(File) != 0) { 488 State(WARN, "Error reading history file '%s' in rpcHandler()", getString()); 489 setData(NULL, 0); // Default response 490 } 491 else setData((void *) Buffer, Size); 492 delete[] Buffer; 493 } 494 495 if (fclose(File) != 0) State(WARN, "Error closing history file '%s' in rpcHandler()", getString()); 478 496 } 479 497 … … 517 535 fread(&New.Next, sizeof(New.Next), 1, File); 518 536 fread(New.Buffer, sizeof(char), New.HistSize, File); 519 fclose(File); 537 if (ferror(File) != 0) State(WARN, "Error reading history file '%s' in AddService()", Name.c_str()); 538 if (fclose(File) != 0) State(WARN, "Error closing history file '%s' in AddService()", Name.c_str());; 520 539 } 521 540 } … … 545 564 fwrite(&(*E).Next, sizeof((*E).Next), 1, File); 546 565 fwrite((*E).Buffer, sizeof(char), (*E).HistSize, File); 547 fclose(File); 566 if (ferror(File) != 0) State(WARN, "Error writing history file '%s' in RemoveService()", Name.c_str()); 567 if (fclose(File) != 0) State(WARN, "Error closing history file '%s' in RemoveService()", Name.c_str());; 548 568 } 549 569 … … 558 578 // Determine size of file in kB 559 579 // 560 float DataHandler::FileSize(FILE *File) {580 off_t DataHandler::FileSize(FILE *File) { 561 581 562 582 struct stat FileStatus; … … 567 587 } 568 588 569 return (float) FileStatus.st_size/1024;589 return FileStatus.st_size; 570 590 } 571 591
Note:
See TracChangeset
for help on using the changeset viewer.
