diff --git a/libraries/DataFlash/DataFlash_File.cpp b/libraries/DataFlash/DataFlash_File.cpp index 69e54e36a48..52b6dc85e4d 100644 --- a/libraries/DataFlash/DataFlash_File.cpp +++ b/libraries/DataFlash/DataFlash_File.cpp @@ -154,7 +154,7 @@ void DataFlash_File::Init() bool DataFlash_File::file_exists(const char *filename) const { #if DATAFLASH_FILE_MINIMAL - int fd = open(filename, O_RDONLY); + int fd = open(filename, O_RDONLY|O_CLOEXEC); if (fd == -1) { return false; } @@ -536,7 +536,7 @@ uint16_t DataFlash_File::find_last_log() if (fname == nullptr) { return ret; } - int fd = open(fname, O_RDONLY); + int fd = open(fname, O_RDONLY|O_CLOEXEC); free(fname); if (fd != -1) { char buf[10]; @@ -651,7 +651,7 @@ int16_t DataFlash_File::get_log_data(const uint16_t list_entry, const uint16_t p return -1; } stop_logging(); - _read_fd = ::open(fname, O_RDONLY); + _read_fd = ::open(fname, O_RDONLY|O_CLOEXEC); if (_read_fd == -1) { _open_error = true; int saved_errno = errno; @@ -804,7 +804,7 @@ uint16_t DataFlash_File::start_new_log(void) if (fname == nullptr) { return 0xFFFF; } - _write_fd = ::open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666); + _write_fd = ::open(fname, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666); _cached_oldest_log = 0; if (_write_fd == -1) { @@ -828,7 +828,7 @@ uint16_t DataFlash_File::start_new_log(void) // we avoid fopen()/fprintf() here as it is not available on as many // systems as open/write (specifically the QURT RTOS) - int fd = open(fname, O_WRONLY|O_CREAT, 0644); + int fd = open(fname, O_WRONLY|O_CREAT|O_CLOEXEC, 0644); free(fname); if (fd == -1) { return 0xFFFF; @@ -873,7 +873,7 @@ void DataFlash_File::LogReadProcess(const uint16_t list_entry, if (fname == nullptr) { return; } - _read_fd = ::open(fname, O_RDONLY); + _read_fd = ::open(fname, O_RDONLY|O_CLOEXEC); free(fname); if (_read_fd == -1) { return; diff --git a/libraries/DataFlash/DataFlash_SITL.cpp b/libraries/DataFlash/DataFlash_SITL.cpp index d3990686f59..3ae175de719 100644 --- a/libraries/DataFlash/DataFlash_SITL.cpp +++ b/libraries/DataFlash/DataFlash_SITL.cpp @@ -31,11 +31,11 @@ void DataFlash_SITL::Init() { DataFlash_Backend::Init(); if (flash_fd == 0) { - flash_fd = open("dataflash.bin", O_RDWR, 0777); + flash_fd = open("dataflash.bin", O_RDWR|O_CLOEXEC, 0777); if (flash_fd == -1) { uint8_t *fill; fill = (uint8_t *)malloc(DF_PAGE_SIZE*DF_NUM_PAGES); - flash_fd = open("dataflash.bin", O_RDWR | O_CREAT, 0777); + flash_fd = open("dataflash.bin", O_RDWR | O_CREAT | O_CLOEXEC, 0777); memset(fill, 0xFF, DF_PAGE_SIZE*DF_NUM_PAGES); write(flash_fd, fill, DF_PAGE_SIZE*DF_NUM_PAGES); free(fill);