-
Notifications
You must be signed in to change notification settings - Fork 618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
save and restore TTY attributes #725
Conversation
279a7ff
to
0f4987e
Compare
add TCSAFLUSH action on exit so tig can't leave behind pending keystrokes
* restore tty attributes from init-time termios * make fseek ... SEEK_END unconditional after command * use TCSAFLUSH when setting tty attributes to block leakage of keystrokes across tig/external boundary - in the "after" case, this is probably more robust than fseek() on the file pointer
void | ||
init_display(void) | ||
{ | ||
bool no_display = !!getenv("TIG_NO_DISPLAY"); | ||
const char *term; | ||
int x, y; | ||
|
||
init_tty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will open /dev/tty
for tests. I think it would be better to skip this if no_display
is true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentionally so — from the point of view of the OS, a TTY is much more than a display.
The TTY is also the medium for the line discipline, in rough terms the interactive input.
A TTY is also inseparable from process-group leadership via tcsetpgrp()
, which among other things determines the disposition of signals, which is relevant under the test harness.
Also, regardless of whether a display is visible, tig is still linked with ncurses, and ncurses maintains a thoroughly TTY-oriented understanding of the world in which it runs. The goal I was driving for here is for ncurses to keep an input-only TTY under no_display
. Tig still does not display anything, but the input "side" of ncurses remains connected to a proper ioctl
able TTY.
The separate matter of process-group leadership becomes relevant when there are long-lived child processes as proposed in #301/#734. The simplest and most robust way to handle child cleanup is to
- be process-group leader
SIGHUP
your own process group at exit.
In the most ordinary case, the interactive shell makes tig the process-group leader transparently, and we don't have to think about it. However, that magic does not happen in non-interactive cases, such as when driven by tig-pick
or the test harness (where no_display
happens to be set). So it is a good idea, when you know you may be invoked from a script, to grab a TTY as a step toward becoming process-group leader.
Congrats on the release!
Thanks a lot for writing down the detailed motivation. |
From: Jonas Fonseca <[email protected]>
To: jonas/tig <[email protected]>
Cc: Subscribed <[email protected]>
Sent: Saturday, September 30, 2017 7:30 PM
Subject: Re: [jonas/tig] save and restore TTY attributes (#725)
Merged #725.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
main program:
opt_tty
becomes a structtcgetattr()
at init timetcsetattr()
indone_display()
TCSAFLUSH
action indone_display()
so that tig can't leave keystrokes behindopen_external_viewer()
, after running external command:TCSAFLUSH
action when restoring tty attributes to block keystrokes leaking in from external command phase - probably more robust thanfseek()
on the file pointerfseek … SEEK_END
, which does no harm, make it unconditionaledit: also set tty attributes and flush before running external command