Skip to content

Commit

Permalink
If the log file was locked, a crash dump was created.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinknafve committed Apr 18, 2015
1 parent f1c2d17 commit a0ea95f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 17 additions & 5 deletions hmailserver/source/Server/Common/Application/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,18 @@ namespace HM
break;
}

bool fileExists = FileUtilities::Exists(fileName);
bool fileExists = false;

try
{
bool fileExists = FileUtilities::Exists(fileName);
}
catch (boost::system::system_error&)
{
// If the log is not accessible for some reason, such as error code 5 - access is denied,
// then we can't open the log file. This will result in nothing being logged.
return nullptr;
}

if (file->IsOpen())
{
Expand All @@ -354,7 +365,8 @@ namespace HM

if (!file->IsOpen())
{
file->Open(fileName, File::OTAppend);
if (!file->Open(fileName, File::OTAppend))
return nullptr;

if (!fileExists && writeUnicode)
{
Expand All @@ -365,12 +377,14 @@ namespace HM
return file;
}

bool
void
Logger::WriteData_(const String &sData, LogType lt)
{
boost::lock_guard<boost::recursive_mutex> guard(mtx_);

File *file = GetCurrentLogFile_(lt);
if (file == nullptr)
return;

bool writeUnicode = false;
bool keepFileOpen = (log_mask_ & LSKeepFilesOpen) && (lt == Normal || lt == SMTP || lt == POP3 || lt == IMAP);
Expand Down Expand Up @@ -417,8 +431,6 @@ namespace HM

if (!keepFileOpen)
file->Close();

return true;
}


Expand Down
2 changes: 1 addition & 1 deletion hmailserver/source/Server/Common/Application/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace HM
File* GetCurrentLogFile_(LogType lt);

void LogLive_(String &sMessage);
bool WriteData_(const String &sData, LogType = Normal);
void WriteData_(const String &sData, LogType = Normal);

static Logger *pInstanceApp;

Expand Down

0 comments on commit a0ea95f

Please sign in to comment.