diff options
| author | memchr <118117622+memchr@users.noreply.github.com> | 2023-08-16 08:51:08 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-16 10:51:08 +0200 |
| commit | 63b266cf6552860403128415c54d91a548434750 (patch) | |
| tree | 1d5f0bcab798a45ade8a7ee60e23d930b9218f80 /src/managers/KeybindManager.cpp | |
| parent | 4986d74ef201171a930c312a8e3b72a22d9b84ee (diff) | |
internal: ioctl use /dev/tty instead of fd 0 for VT_GETSTATE (#2989)
* fix: ioctl use /dev/tty instead of fd 0 for VT_GETSTATE
ioctl VT_GETSTATE on stdin fails if it is not console, such as when
using GDM. `/dev/tty` should be used instead.
- `/dev/tty` is a synonym for the controlling terminal of a process, if
there is one.
---------
Co-authored-by: Jan Beich <jbeich@FreeBSD.org>
Diffstat (limited to 'src/managers/KeybindManager.cpp')
| -rw-r--r-- | src/managers/KeybindManager.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 6956c697..2a44137e 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -3,6 +3,7 @@ #include <regex> #include <sys/ioctl.h> +#include <fcntl.h> #if defined(__linux__) #include <linux/vt.h> #elif defined(__NetBSD__) || defined(__OpenBSD__) @@ -518,15 +519,19 @@ bool CKeybindManager::handleVT(xkb_keysym_t keysym) { // vtnr is bugged for some reason. unsigned int ttynum = 0; + int fd; + if ((fd = open("/dev/tty", O_RDONLY | O_NOCTTY)) >= 0) { #if defined(VT_GETSTATE) - struct vt_stat st; - if (!ioctl(0, VT_GETSTATE, &st)) - ttynum = st.v_active; + struct vt_stat st; + if (!ioctl(fd, VT_GETSTATE, &st)) + ttynum = st.v_active; #elif defined(VT_GETACTIVE) - int vt; - if (!ioctl(0, VT_GETACTIVE, &vt)) - ttynum = vt; + int vt; + if (!ioctl(fd, VT_GETACTIVE, &vt)) + ttynum = vt; #endif + close(fd); + } if (ttynum == TTY) return true; |
