vezel-dev / cathode

A terminal-centric replacement for the .NET console APIs.
https://docs.vezel.dev/cathode
BSD Zero Clause License
91 stars 7 forks source link

Handle `SIGTTOU` when switching to cooked mode on Unix #42

Closed alexrp closed 2 years ago

alexrp commented 2 years ago

Currently, when we call tcsetattr during driver initialization to ensure we're in cooked mode, we can be suspended by a SIGTTOU if we're a background process. The question is: Should we handle SIGTTOU instead (so that we don't get suspended) and just proceed, trusting that the terminal is probably in cooked mode?

Arguably, this is probably fine most of the time. But what about the times when the foreground process is in raw mode and we end up completely garbling the screen? I'm not sure there's really a 'correct' answer. Need to think more on this.

Useful reference: http://curiousthing.org/sigttin-sigttou-deep-dive-linux

alexrp commented 2 years ago

One option would be to compare the current termios values to our desired values and only call tcsetattr if they differ.

The obvious downsides here are:

alexrp commented 2 years ago

But what about the times when the foreground process is in raw mode and we end up completely garbling the screen?

Such an application should really set TOSTOP (which we would be forced to respect as we can't block/ignore SIGTTOU from managed land anyway). See:

alexrp commented 2 years ago

I think I'm satisfied that there would be no major issues with just assuming we're in cooked mode. I think it's entirely reasonable to say that if a parent process launches a child process in raw mode, the developer of the parent process is doing it wrong. Nobody expects their program to launch in raw mode.