Skip to content

Make tig the process group leader and automatically clean child processes #828

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

Merged
merged 2 commits into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


Options
-------

Expand Down