Skip to content

Commit

Permalink
Add error handling on closing logfile
Browse files Browse the repository at this point in the history
It has happened in the field because of an unknown reason.
  • Loading branch information
halfgaar committed Nov 4, 2023
1 parent abbdc0c commit 55c50aa
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,15 @@ void Logger::reOpen()

if (file)
{
fclose(file);
// Any further use of 'file' is undefined behavior, including closing again, so we just have to abandon it.
const int rc = fclose(file);
file = nullptr;

if (rc != 0)
{
const std::string err(strerror(errno));
log(LOG_ERR) << "Closing the log file failed with: " << err << ". Depending on whether it can be reopened again, logging may continue on stdout.";
}
}

if (logPath.empty())
Expand Down

0 comments on commit 55c50aa

Please sign in to comment.