From 63b266cf6552860403128415c54d91a548434750 Mon Sep 17 00:00:00 2001 From: memchr <118117622+memchr@users.noreply.github.com> Date: Wed, 16 Aug 2023 08:51:08 +0000 Subject: [PATCH] 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 --- src/managers/KeybindManager.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 6956c6972..2a44137e7 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -3,6 +3,7 @@ #include #include +#include #if defined(__linux__) #include #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;