Browse Source

AP_HAL_SITL: add O_CLOEXEC in places missing it

By opening with O_CLOEXEC we make sure we don't leak the file descriptor
when we are exec'ing or calling out subprograms. Right now we currently
don't do it so there's no harm, but it's good practice in Linux to have
it.
master
Lucas De Marchi 8 years ago
parent
commit
f6d475c1e6
  1. 2
      libraries/AP_HAL_SITL/Storage.cpp
  2. 2
      libraries/AP_HAL_SITL/sitl_gps.cpp
  3. 2
      libraries/SITL/SIM_JSBSim.cpp
  4. 2
      libraries/SITL/SIM_last_letter.cpp

2
libraries/AP_HAL_SITL/Storage.cpp

@ -13,7 +13,7 @@ using namespace HALSITL; @@ -13,7 +13,7 @@ using namespace HALSITL;
void EEPROMStorage::_eeprom_open(void)
{
if (_eeprom_fd == -1) {
_eeprom_fd = open("eeprom.bin", O_RDWR|O_CREAT, 0777);
_eeprom_fd = open("eeprom.bin", O_RDWR|O_CREAT|O_CLOEXEC, 0777);
assert(ftruncate(_eeprom_fd, HAL_STORAGE_SIZE) == 0);
}
}

2
libraries/AP_HAL_SITL/sitl_gps.cpp

@ -902,7 +902,7 @@ void SITL_State::_update_gps_file(const struct gps_data *d) @@ -902,7 +902,7 @@ void SITL_State::_update_gps_file(const struct gps_data *d)
{
static int fd = -1;
if (fd == -1) {
fd = open("/tmp/gps.dat", O_RDONLY);
fd = open("/tmp/gps.dat", O_RDONLY|O_CLOEXEC);
}
if (fd == -1) {
return;

2
libraries/SITL/SIM_JSBSim.cpp

@ -173,7 +173,7 @@ bool JSBSim::start_JSBSim(void) @@ -173,7 +173,7 @@ bool JSBSim::start_JSBSim(void)
}
int p[2];
int devnull = open("/dev/null", O_RDWR);
int devnull = open("/dev/null", O_RDWR|O_CLOEXEC);
if (pipe(p) != 0) {
AP_HAL::panic("Unable to create pipe");
}

2
libraries/SITL/SIM_last_letter.cpp

@ -55,7 +55,7 @@ void last_letter::start_last_letter(void) @@ -55,7 +55,7 @@ void last_letter::start_last_letter(void)
if (child_pid == 0) {
// in child
close(0);
open("/dev/null", O_RDONLY);
open("/dev/null", O_RDONLY|O_CLOEXEC);
for (uint8_t i=3; i<100; i++) {
close(i);
}

Loading…
Cancel
Save