Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions rdkPlugins/Logging/source/FileSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ FileSink::FileSink(const std::string &containerId, std::shared_ptr<rt_dobby_sche
{
// Couldn't open our output file, send to /dev/null to avoid blocking
AI_LOG_SYS_ERROR(errno, "Failed to open container logfile - sending to /dev/null");
if (mDevNullFd > 0)
if (mDevNullFd >= 0)
{
mOutputFileFd = mDevNullFd;
}
Expand All @@ -88,17 +88,20 @@ FileSink::FileSink(const std::string &containerId, std::shared_ptr<rt_dobby_sche

FileSink::~FileSink()
{
// Close everything we opened
if (close(mDevNullFd) < 0)
// Close everything we opened; avoid closing the same fd twice
if (mOutputFileFd >= 0 && mOutputFileFd != mDevNullFd)
{
AI_LOG_SYS_ERROR(errno, "Failed to close /dev/null");
if (close(mOutputFileFd) < 0)
{
AI_LOG_SYS_ERROR(errno, "Failed to close output file");
}
}

if (mOutputFileFd > 0)
if (mDevNullFd >= 0)
{
if (close(mOutputFileFd) < 0)
if (close(mDevNullFd) < 0)
{
AI_LOG_SYS_ERROR(errno, "Failed to close output file");
AI_LOG_SYS_ERROR(errno, "Failed to close /dev/null");
}
}
}
Expand Down Expand Up @@ -264,4 +267,4 @@ int FileSink::openFile(const std::string &pathName)
}

return openedFd;
}
}
Loading