Skip to content
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

Merged
merged 2 commits into from
Sep 30, 2017
Merged

save and restore TTY attributes #725

merged 2 commits into from
Sep 30, 2017

Conversation

rolandwalker
Copy link
Contributor

@rolandwalker rolandwalker commented Aug 14, 2017

main program:

  • opt_tty becomes a struct
  • tcgetattr() at init time
  • tcsetattr() in done_display()
  • specify TCSAFLUSH action in done_display() so that tig can't leave keystrokes behind

open_external_viewer(), after running external command:

  • restore init-time tty attributes before duplicating ncurses setup steps
  • use TCSAFLUSH action when restoring tty attributes to block keystrokes leaking in from external command phase - probably more robust than fseek() on the file pointer
  • but keep fseek … SEEK_END, which does no harm, make it unconditional

edit: also set tty attributes and flush before running external command

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();
Copy link
Owner

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.

Copy link
Contributor Author

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 ioctlable 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

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!

@jonas jonas merged commit 35af931 into jonas:master Sep 30, 2017
@jonas
Copy link
Owner

jonas commented Sep 30, 2017

Thanks a lot for writing down the detailed motivation.

@rolandwalker rolandwalker deleted the termios branch September 30, 2017 23:56
@sampittibul
Copy link

sampittibul commented Oct 1, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants