mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-28 06:46:38 -04:00
input: keymap(): use a goto-label on error, to ensure we always close the keymap FD
This commit is contained in:
parent
82e75851e4
commit
5587604469
1 changed files with 8 additions and 9 deletions
17
input.c
17
input.c
|
|
@ -576,23 +576,20 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
|
||||||
/* Verify keymap is in a format we understand */
|
/* Verify keymap is in a format we understand */
|
||||||
switch ((enum wl_keyboard_keymap_format)format) {
|
switch ((enum wl_keyboard_keymap_format)format) {
|
||||||
case WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP:
|
case WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP:
|
||||||
close(fd);
|
goto err;
|
||||||
return;
|
|
||||||
|
|
||||||
case WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1:
|
case WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
LOG_WARN("unrecognized keymap format: %u", format);
|
LOG_WARN("unrecognized keymap format: %u", format);
|
||||||
close(fd);
|
goto err;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *map_str = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
|
char *map_str = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||||
if (map_str == MAP_FAILED) {
|
if (map_str == MAP_FAILED) {
|
||||||
LOG_ERRNO("failed to mmap keyboard keymap");
|
LOG_ERRNO("failed to mmap keyboard keymap");
|
||||||
close(fd);
|
goto err;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (map_str[size - 1] == '\0')
|
while (map_str[size - 1] == '\0')
|
||||||
|
|
@ -605,6 +602,8 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
munmap(map_str, size);
|
||||||
|
|
||||||
if (seat->kbd.xkb_keymap != NULL) {
|
if (seat->kbd.xkb_keymap != NULL) {
|
||||||
seat->kbd.xkb_state = xkb_state_new(seat->kbd.xkb_keymap);
|
seat->kbd.xkb_state = xkb_state_new(seat->kbd.xkb_keymap);
|
||||||
|
|
||||||
|
|
@ -685,10 +684,10 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
|
||||||
seat->kbd.key_arrow_down = xkb_keymap_key_by_name(seat->kbd.xkb_keymap, "DOWN");
|
seat->kbd.key_arrow_down = xkb_keymap_key_by_name(seat->kbd.xkb_keymap, "DOWN");
|
||||||
}
|
}
|
||||||
|
|
||||||
munmap(map_str, size);
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
key_binding_load_keymap(wayl->key_binding_manager, seat);
|
key_binding_load_keymap(wayl->key_binding_manager, seat);
|
||||||
|
|
||||||
|
err:
|
||||||
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue