Skip to content

Commit e9a7a3f

Browse files
authored
Console.Unix: fix missing terminal configuration on SIGINT/SIGQUIT/SIGCONT. (#64200)
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.
1 parent 3e4acf4 commit e9a7a3f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/native/libs/System.Native/pal_signal.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,16 @@ int32_t InitializeSignalHandlingCore()
584584
return 0;
585585
}
586586

587+
#ifdef HAS_CONSOLE_SIGNALS
588+
// Unconditionally register signals for terminal configuration.
589+
bool installed = InstallSignalHandler(SIGINT, SA_RESTART);
590+
assert(installed);
591+
installed = InstallSignalHandler(SIGQUIT, SA_RESTART);
592+
assert(installed);
593+
installed = InstallSignalHandler(SIGCONT, SA_RESTART);
594+
assert(installed);
595+
#endif
596+
587597
return 1;
588598
}
589599

@@ -612,7 +622,12 @@ void SystemNative_DisablePosixSignalHandling(int signalCode)
612622
{
613623
g_hasPosixSignalRegistrations[signalCode - 1] = false;
614624

615-
if (!(g_consoleTtouHandler && signalCode == SIGTTOU) &&
625+
// Don't restore handler when something other than posix handling needs the signal.
626+
if (
627+
#ifdef HAS_CONSOLE_SIGNALS
628+
signalCode != SIGINT && signalCode != SIGQUIT && signalCode != SIGCONT &&
629+
#endif
630+
!(g_consoleTtouHandler && signalCode == SIGTTOU) &&
616631
!(g_sigChldCallback && signalCode == SIGCHLD) &&
617632
!(g_terminalInvalidationCallback && (signalCode == SIGCONT ||
618633
signalCode == SIGCHLD ||

0 commit comments

Comments
 (0)