Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set O_EXCL when opening file with include_excl #666

Merged
merged 1 commit into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions Os/Linux/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ namespace Os {
#endif
case OPEN_CREATE:
flags = O_WRONLY | O_CREAT | O_TRUNC;
if(include_excl) {
flags |= O_EXCL;
}
break;
case OPEN_APPEND:
flags = O_WRONLY | O_CREAT | O_APPEND;
Expand Down
3 changes: 3 additions & 0 deletions Os/Stubs/Linux/FileStub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ namespace Os {
break;
case OPEN_CREATE:
flags = O_WRONLY | O_CREAT | O_TRUNC;
if(include_excl) {
flags |= O_EXCL;
}
break;
default:
FW_ASSERT(0,(NATIVE_INT_TYPE)mode);
Expand Down
3 changes: 1 addition & 2 deletions Svc/ActiveTextLogger/LogFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ namespace Svc {
}

// Open the file (using CREATE so that it truncates an already existing file):
Os::File::Status stat = this->m_file.open(fileNameFinal,
Os::File::OPEN_CREATE);
Os::File::Status stat = this->m_file.open(fileNameFinal, Os::File::OPEN_CREATE, false);

// Bad status when trying to open the file:
if (stat != Os::File::OP_OK) {
Expand Down
20 changes: 10 additions & 10 deletions Svc/ActiveTextLogger/test/ut/Tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
namespace Svc {

// ----------------------------------------------------------------------
// Construction and destruction
// Construction and destruction
// ----------------------------------------------------------------------

Tester ::
Tester(void) :
Tester(void) :
#if FW_OBJECT_NAMES == 1
ActiveTextLoggerGTestBase("Tester", MAX_HISTORY_SIZE),
component("ActiveTextLogger")
Expand All @@ -32,13 +32,13 @@ namespace Svc {
}

Tester ::
~Tester(void)
~Tester(void)
{

}

// ----------------------------------------------------------------------
// Tests
// Tests
// ----------------------------------------------------------------------

void Tester ::
Expand Down Expand Up @@ -181,7 +181,7 @@ namespace Svc {

ASSERT_TRUE(stat);
ASSERT_TRUE(this->component.m_log_file.m_openFile);
ASSERT_EQ(0,strcmp("test_file_max",this->component.m_log_file.m_fileName.toChar()));
ASSERT_STREQ("test_file_max",this->component.m_log_file.m_fileName.toChar());
ASSERT_EQ(0U, this->component.m_log_file.m_currentFileSize);
ASSERT_EQ(45U, this->component.m_log_file.m_maxFileSize);
ASSERT_EQ(Os::FileSystem::OP_OK,
Expand Down Expand Up @@ -249,7 +249,7 @@ namespace Svc {
// Verify made file with 0 suffix:
ASSERT_TRUE(stat);
ASSERT_TRUE(this->component.m_log_file.m_openFile);
ASSERT_EQ(0,strcmp("test_file_max0",this->component.m_log_file.m_fileName.toChar()));
ASSERT_STREQ("test_file_max0",this->component.m_log_file.m_fileName.toChar());
ASSERT_EQ(0U, this->component.m_log_file.m_currentFileSize);
ASSERT_EQ(50U, this->component.m_log_file.m_maxFileSize);
ASSERT_EQ(Os::FileSystem::OP_OK,
Expand Down Expand Up @@ -353,11 +353,11 @@ namespace Svc {
}

// ----------------------------------------------------------------------
// Helper methods
// Helper methods
// ----------------------------------------------------------------------

void Tester ::
connectPorts(void)
connectPorts(void)
{

// TextLogger
Expand All @@ -372,7 +372,7 @@ namespace Svc {
}

void Tester ::
initComponents(void)
initComponents(void)
{
this->init();
this->component.init(
Expand Down