Make sure SDL file descriptors don't leak into child processes

This commit is contained in:
Sam Lantinga
2021-09-08 14:47:40 -07:00
parent 3ed8ba7d33
commit bf97c5a22f
15 changed files with 24 additions and 24 deletions

View File

@@ -238,7 +238,7 @@ SDL_EVDEV_kbd_init(void)
kbd->npadch = -1;
/* This might fail if we're not connected to a tty (e.g. on the Steam Link) */
kbd->keyboard_fd = kbd->console_fd = open("/dev/tty", O_RDONLY);
kbd->keyboard_fd = kbd->console_fd = open("/dev/tty", O_RDONLY | O_CLOEXEC);
kbd->shift_state = 0;
@@ -274,7 +274,7 @@ SDL_EVDEV_kbd_init(void)
*/
ioctl(kbd->console_fd, CONS_RELKBD, 1ul);
asprintf(&devicePath, "/dev/kbd%d", kbd->kbInfo->kb_index);
kbd->keyboard_fd = open(devicePath, O_WRONLY);
kbd->keyboard_fd = open(devicePath, O_WRONLY | O_CLOEXEC);
if (kbd->keyboard_fd == -1)
{
// Give keyboard back.

View File

@@ -725,7 +725,7 @@ SDL_EVDEV_device_added(const char *dev_path, int udev_class)
return SDL_OutOfMemory();
}
item->fd = open(dev_path, O_RDONLY | O_NONBLOCK);
item->fd = open(dev_path, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
if (item->fd < 0) {
SDL_free(item);
return SDL_SetError("Unable to open %s", dev_path);

View File

@@ -354,7 +354,7 @@ SDL_EVDEV_kbd_init(void)
kbd->npadch = -1;
/* This might fail if we're not connected to a tty (e.g. on the Steam Link) */
kbd->console_fd = open("/dev/tty", O_RDONLY);
kbd->console_fd = open("/dev/tty", O_RDONLY | O_CLOEXEC);
if (ioctl(kbd->console_fd, TIOCLINUX, shift_state) == 0) {
kbd->shift_state = *shift_state;

View File

@@ -416,7 +416,7 @@ static SDL_WSCONS_input_data* SDL_WSCONS_Init_Keyboard(const char* dev)
if (!input) {
return input;
}
input->fd = open(dev,O_RDWR | O_NONBLOCK);
input->fd = open(dev,O_RDWR | O_NONBLOCK | O_CLOEXEC);
if (input->fd == -1) {
free(input);
input = NULL;

View File

@@ -43,7 +43,7 @@ SDL_WSCONS_mouse_input_data* SDL_WSCONS_Init_Mouse()
SDL_WSCONS_mouse_input_data* mouseInputData = SDL_calloc(1, sizeof(SDL_WSCONS_mouse_input_data));
if (!mouseInputData) return NULL;
mouseInputData->fd = open("/dev/wsmouse",O_RDWR | O_NONBLOCK);
mouseInputData->fd = open("/dev/wsmouse",O_RDWR | O_NONBLOCK | O_CLOEXEC);
if (mouseInputData->fd == -1) {free(mouseInputData); return NULL; }
#ifdef WSMOUSEIO_SETMODE
ioctl(mouseInputData->fd, WSMOUSEIO_SETMODE, WSMOUSE_COMPAT);