From 53384ed5eea5fead452b20a84b7db7fe45afb059 Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Wed, 24 Apr 2019 13:15:56 +0000 Subject: [PATCH] Fix some races and screeen clearing in VGLEnd(). The mouse signal SIGUSR2 was not turned off for normal termination and in some other cases. Thus mouse signals arriving after the frame buffer was unmapped always caused fatal traps. The fatal traps occurred about 1 time in 5 if the mouse was wiggled while vgl is ending. The screen switch signal SIGUSR1 was turned off after clearing the flag that it sets. Unlike the mouse signal, this signal is handled synchronously, but VGLEnd() does screen clearing which does the synchronous handling. This race is harder to lose. I think it can get vgl into deadlocked state (waiting in the screen switch handler with SIGUSR1 to leave that state already turned off). Turn off the mouse cursor before clearing the screen in VGLEnd(). Otherwise, clearing is careful to not clear the mouse cursor. Undrawing an active mouse cursor uses a lot of state, so is dangerous for abnormal termination, but so is clearing. Clearing is slow and is usually not needed, since the kernel also does it (not quite right). --- lib/libvgl/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/libvgl/main.c b/lib/libvgl/main.c index 354e45bc6d51..63a3247b6e77 100644 --- a/lib/libvgl/main.c +++ b/lib/libvgl/main.c @@ -73,11 +73,11 @@ struct vt_mode smode; if (!VGLInitDone) return; - VGLInitDone = 0; + signal(SIGUSR1, SIG_IGN); + signal(SIGUSR2, SIG_IGN); VGLSwitchPending = 0; VGLAbortPending = 0; - - signal(SIGUSR1, SIG_IGN); + VGLMousePointerHide(); if (VGLMem != MAP_FAILED) { VGLClear(VGLDisplay, 0);