diff --git a/include/tig/display.h b/include/tig/display.h index b44579868..b76dd19b8 100644 --- a/include/tig/display.h +++ b/include/tig/display.h @@ -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); diff --git a/src/display.c b/src/display.c index 265a3a056..5d706bf1d 100644 --- a/src/display.c +++ b/src/display.c @@ -584,7 +584,7 @@ set_terminal_modes(void) leaveok(stdscr, false); } -static void +void init_tty(void) { /* open */ @@ -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 @@ -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)) diff --git a/src/tig.c b/src/tig.c index d3c1da8e6..7b9e417b8 100644 --- a/src/tig.c +++ b/src/tig.c @@ -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");