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.
This commit is contained in:
parent
c9eff28c44
commit
f6d475c1e6
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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…
Reference in New Issue
Block a user