From ebd62f24faa09b75c15d60da73331cb496cf50a7 Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Mon, 24 Jan 2022 11:10:25 +0100 Subject: [PATCH] Console.Unix: fix missing terminal configuration on SIGINT/SIGQUIT/SIGCONT. The introduction of the managed API for signal handling (PosixSignal) inadvertently caused terminal configuration to no longer be performed when no managed handlers are registered. This adds back the unconditional registration for SIGINT/SIGQUIT/SIGCONT. The missing registrations can cause the terminal to stop echoing when an application terminates on Ctrl-C. --- .../Native/Unix/System.Native/pal_signal.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/libraries/Native/Unix/System.Native/pal_signal.c b/src/libraries/Native/Unix/System.Native/pal_signal.c index 6e7243fca17eee..fb9628382762e4 100644 --- a/src/libraries/Native/Unix/System.Native/pal_signal.c +++ b/src/libraries/Native/Unix/System.Native/pal_signal.c @@ -584,6 +584,16 @@ int32_t InitializeSignalHandlingCore() return 0; } +#ifdef HAS_CONSOLE_SIGNALS + // Unconditionally register signals for terminal configuration. + bool installed = InstallSignalHandler(SIGINT, SA_RESTART); + assert(installed); + installed = InstallSignalHandler(SIGQUIT, SA_RESTART); + assert(installed); + installed = InstallSignalHandler(SIGCONT, SA_RESTART); + assert(installed); +#endif + return 1; } @@ -612,7 +622,12 @@ void SystemNative_DisablePosixSignalHandling(int signalCode) { g_hasPosixSignalRegistrations[signalCode - 1] = false; - if (!(g_consoleTtouHandler && signalCode == SIGTTOU) && + // Don't restore handler when something other than posix handling needs the signal. + if ( +#ifdef HAS_CONSOLE_SIGNALS + signalCode != SIGINT && signalCode != SIGQUIT && signalCode != SIGCONT && +#endif + !(g_consoleTtouHandler && signalCode == SIGTTOU) && !(g_sigChldCallback && signalCode == SIGCHLD) && !(g_terminalInvalidationCallback && (signalCode == SIGCONT || signalCode == SIGCHLD ||