mlog: don't remove old logs if we failed to rename the current file

Coverity 188348
This commit is contained in:
moneromooo-monero 2018-09-27 14:58:55 +00:00
parent 5fdcda50ee
commit 661439f4e0
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3
1 changed files with 6 additions and 1 deletions

View File

@ -137,7 +137,12 @@ void mlog_configure(const std::string &filename_base, bool console, const std::s
el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck); el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck);
el::Helpers::installPreRollOutCallback([filename_base, max_log_files](const char *name, size_t){ el::Helpers::installPreRollOutCallback([filename_base, max_log_files](const char *name, size_t){
std::string rname = generate_log_filename(filename_base.c_str()); std::string rname = generate_log_filename(filename_base.c_str());
rename(name, rname.c_str()); int ret = rename(name, rname.c_str());
if (ret < 0)
{
// can't log a failure, but don't do the file removal below
return;
}
if (max_log_files != 0) if (max_log_files != 0)
{ {
std::vector<boost::filesystem::path> found_files; std::vector<boost::filesystem::path> found_files;