| 552 | -------------------------------------------------------------------------*/ |
| 553 | |
| 554 | void |
| 555 | LogConfig::update_space_used() |
| 556 | { |
| 557 | // no need to update space used if log directory is inaccessible |
| 558 | // |
| 559 | if (m_log_directory_inaccessible) { |
| 560 | return; |
| 561 | } |
| 562 | |
| 563 | int64_t total_space_used, partition_space_left; |
| 564 | char path[MAXPATHLEN]; |
| 565 | int sret; |
| 566 | struct dirent *entry; |
| 567 | struct stat sbuf; |
| 568 | DIR *ld; |
| 569 | |
| 570 | // check if logging directory has been specified |
| 571 | // |
| 572 | if (!logfile_dir) { |
| 573 | const char *msg = "Logging directory not specified"; |
| 574 | Error("%s", msg); |
| 575 | m_log_directory_inaccessible = true; |
| 576 | return; |
| 577 | } |
| 578 | |
| 579 | // check if logging directory exists and is searchable readable & writable |
| 580 | int err; |
| 581 | do { |
| 582 | err = access(logfile_dir, R_OK | W_OK | X_OK); |
| 583 | } while ((err < 0) && (errno == EINTR)); |
| 584 | |
| 585 | if (err < 0) { |
| 586 | const char *msg = "Error accessing logging directory %s: %s."; |
| 587 | Error(msg, logfile_dir, strerror(errno)); |
| 588 | m_log_directory_inaccessible = true; |
| 589 | return; |
| 590 | } |
| 591 | |
| 592 | ld = ::opendir(logfile_dir); |
| 593 | if (ld == nullptr) { |
| 594 | const char *msg = "Error opening logging directory %s to perform a space check: %s."; |
| 595 | Error(msg, logfile_dir, strerror(errno)); |
| 596 | m_log_directory_inaccessible = true; |
| 597 | return; |
| 598 | } |
| 599 | |
| 600 | total_space_used = 0LL; |
| 601 | |
| 602 | while ((entry = readdir(ld))) { |
| 603 | snprintf(path, MAXPATHLEN, "%s/%s", logfile_dir, entry->d_name); |
| 604 | |
| 605 | sret = ::stat(path, &sbuf); |
| 606 | if (sret != -1 && S_ISREG(sbuf.st_mode)) { |
| 607 | total_space_used += static_cast<int64_t>(sbuf.st_size); |
| 608 | |
| 609 | if (auto_delete_rolled_files && LogFile::rolled_logfile(entry->d_name)) { |
| 610 | rolledLogDeleter.consider_for_candidacy(path, sbuf.st_size, sbuf.st_mtime); |
| 611 | } |
no test coverage detected