From effac744c75440e8d7e602ef38a321b2264b6cb6 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 2 Apr 2026 21:00:49 -0500 Subject: [PATCH] Fix handling close(0) in our DRM master hooks Prior to this fix, we would become out of sync and fail to promote Qt and SDL FDs to master when required, causing Qt's mouse to disappear and the SDL video subsystem to fail initialization when trying to stream. --- app/masterhook_internal.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/masterhook_internal.c b/app/masterhook_internal.c index 1c56fe2d..8fc087ce 100644 --- a/app/masterhook_internal.c +++ b/app/masterhook_internal.c @@ -34,7 +34,7 @@ extern struct stat g_DrmMasterStat; extern bool g_DisableDrmHooks; #define MAX_SDL_FD_COUNT 8 -int g_SdlDrmMasterFds[MAX_SDL_FD_COUNT]; +int g_SdlDrmMasterFds[MAX_SDL_FD_COUNT] = {-1, -1, -1, -1, -1, -1, -1, -1}; int g_SdlDrmMasterFdCount = 0; pthread_mutex_t g_FdTableLock = PTHREAD_MUTEX_INITIALIZER; @@ -58,6 +58,13 @@ int getSdlFdEntryIndex(bool unused) // Returns true if the final SDL FD was removed bool removeSdlFd(int fd) { + // -1 will break our logic below that looks for matches + // in the entire array (which we must do because it may + // not be contiguously populated). + if (fd == -1) { + return false; + } + pthread_mutex_lock(&g_FdTableLock); if (g_SdlDrmMasterFdCount != 0) { // Clear the entry for this fd from the table