Skip to content
Merged
Changes from all commits
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
24 changes: 16 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 All @@ -117,6 +120,11 @@ void FileSink::DumpLog(const int bufferFd)

std::lock_guard<std::mutex> locker(mLock);

if (mOutputFileFd < 0) {
AI_LOG_ERROR("Invalid output file descriptor");
return;
}

ssize_t ret;
ssize_t offset = 0;

Expand Down Expand Up @@ -264,4 +272,4 @@ int FileSink::openFile(const std::string &pathName)
}

return openedFd;
}
}
Loading