Skip to content

Commit

Permalink
Merge pull request #828 from rolandwalker/process-group-leader
Browse files Browse the repository at this point in the history
Make tig the process group leader and automatically clean child processes
  • Loading branch information
jonas authored May 21, 2018
2 parents 4fbfb71 + ccbda97 commit 1aad1b9
Show file tree
Hide file tree
Showing 4 changed files with 25 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
12 changes: 12 additions & 0 deletions src/tig.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,14 @@ die_if_failed(enum status_code code, const char *msg)
die("%s: %s", msg, get_status_message(code));
}

void
hangup_children(void)
{
if (signal(SIGHUP, SIG_IGN) == SIG_ERR)
return;
killpg(getpid(), SIGHUP);
}

static inline enum status_code
handle_git_prefix(void)
{
Expand Down Expand Up @@ -772,6 +780,10 @@ main(int argc, const char *argv[])
enum request request = parse_options(argc, argv, pager_mode);
struct view *view;

init_tty();

atexit(hangup_children);

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

Expand Down
3 changes: 3 additions & 0 deletions test/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ test scripts as long as `PATH` is set to include the directories `src/`
and `test/tools`. The latter directory is where the test helper
libraries are located, the most important of which is `libtest.sh`.

The test suite requires `stty -tostop` to be set in the running terminal,
which is typically the default.

Options
-------

Expand Down

0 comments on commit 1aad1b9

Please sign in to comment.