Skip to content

Commit

Permalink
make tig the process-group leader
Browse files Browse the repository at this point in the history
and give it the foreground connection to the TTY.  This announces to
the OS "I am an interactive program taking input".  In the most common
case, this will already have been arranged by the user's shell.

Setting this explicitly is useful when running under the test harness
or a script like tig-pick.

This init is logically done as early as possible, as child processes
inherit these characteristics.

This also allows tig to easily ensure child process cleanup at exit.
  • Loading branch information
rolandwalker committed May 21, 2018
1 parent 877092e commit b70d333
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/tig/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ extern unsigned int current_view;
#define view_is_displayed(view) \
(view == display[0] || view == display[1])

void init_tty(void);
void init_display(void);
void resize_display(void);
void redraw_display(bool clear);
Expand Down
11 changes: 9 additions & 2 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ set_terminal_modes(void)
leaveok(stdscr, false);
}

static void
void
init_tty(void)
{
/* open */
Expand All @@ -598,6 +598,12 @@ init_tty(void)
if (!opt_tty.attr)
die("Failed allocation for tty attributes");
tcgetattr(opt_tty.fd, opt_tty.attr);

/* process-group leader */
signal(SIGTTOU, SIG_IGN);
setpgid(getpid(), getpid());
tcsetpgrp(opt_tty.fd, getpid());
signal(SIGTTOU, SIG_DFL);
}

void
Expand All @@ -607,7 +613,8 @@ init_display(void)
const char *term;
int x, y;

init_tty();
if (!opt_tty.file)
die("Can't initialize display without tty");

die_callback = done_display;
if (atexit(done_display))
Expand Down
2 changes: 2 additions & 0 deletions src/tig.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,8 @@ main(int argc, const char *argv[])
enum request request = parse_options(argc, argv, pager_mode);
struct view *view;

init_tty();

if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
die("Failed to setup signal handler");

Expand Down

0 comments on commit b70d333

Please sign in to comment.