mirror of
https://github.com/encounter/SDL.git
synced 2025-12-08 21:17:45 +00:00
Make sure SDL file descriptors don't leak into child processes
This commit is contained in:
@@ -240,7 +240,7 @@ BSD_JoystickInit(void)
|
||||
}
|
||||
for (i = 0; i < MAX_JOY_JOYS; i++) {
|
||||
SDL_snprintf(s, SDL_arraysize(s), "/dev/joy%d", i);
|
||||
fd = open(s, O_RDONLY);
|
||||
fd = open(s, O_RDONLY | O_CLOEXEC);
|
||||
if (fd != -1) {
|
||||
joynames[numjoysticks++] = SDL_strdup(s);
|
||||
close(fd);
|
||||
@@ -357,7 +357,7 @@ BSD_JoystickOpen(SDL_Joystick *joy, int device_index)
|
||||
int fd;
|
||||
int i;
|
||||
|
||||
fd = open(path, O_RDONLY);
|
||||
fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||
if (fd == -1) {
|
||||
return SDL_SetError("%s: %s", path, strerror(errno));
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ MaybeAddDevice(const char *path)
|
||||
}
|
||||
}
|
||||
|
||||
fd = open(path, O_RDONLY, 0);
|
||||
fd = open(path, O_RDONLY | O_CLOEXEC, 0);
|
||||
if (fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -963,7 +963,7 @@ PrepareJoystickHwdata(SDL_Joystick *joystick, SDL_joylist_item *item)
|
||||
&joystick->naxes,
|
||||
&joystick->nhats);
|
||||
} else {
|
||||
const int fd = open(item->path, O_RDWR, 0);
|
||||
const int fd = open(item->path, O_RDWR | O_CLOEXEC, 0);
|
||||
if (fd < 0) {
|
||||
return SDL_SetError("Unable to open %s", item->path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user