Skip to content

Commit

Permalink
Make tig process-group leader an option
Browse files Browse the repository at this point in the history
To make tig process-group leader, activate option pgrp in tigrc.

Closes #986, closes #951
  • Loading branch information
koutcher committed Feb 25, 2020
1 parent b824232 commit 02bfeb4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
8 changes: 8 additions & 0 deletions doc/tigrc.5.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,14 @@ The following variables can be set:
Mouse support requires that ncurses itself support mouse events and that
you have enabled mouse support in ~/.tigrc with `set mouse = true`.
'pgrp' (bool)::
Make tig process-group leader when starting and clean all processes
when exiting. Off by default. Do not enable this option if you are
using a Zsh version affected by zsh-workers/43379. Run `xclip` with
`setsid` to keep clipboard content after exiting tig. If you are using
git-credential-cache helper, set option `credentialCache.ignoreSIGHUP`.
'start-on-head' (bool)::
Start with cursor on HEAD commit.
Expand Down
1 change: 1 addition & 0 deletions include/tig/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typedef struct view_column *view_settings;
_(mouse_scroll, int, VIEW_NO_FLAGS) \
_(mouse_wheel_cursor, bool, VIEW_NO_FLAGS) \
_(pager_view, view_settings, VIEW_NO_FLAGS) \
_(pgrp, bool, VIEW_NO_FLAGS) \
_(reference_format, struct ref_format **, VIEW_NO_FLAGS) \
_(refresh_interval, int, VIEW_NO_FLAGS) \
_(refresh_mode, enum refresh_mode, VIEW_NO_FLAGS) \
Expand Down
22 changes: 13 additions & 9 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,11 @@ done_display(void)
free(opt_tty.attr);
opt_tty.attr = NULL;
}
signal(SIGTTOU, SIG_IGN);
tcsetpgrp(opt_tty.fd, opt_tty.opgrp);
signal(SIGTTOU, SIG_DFL);
if (opt_tty.opgrp != -1) {
signal(SIGTTOU, SIG_IGN);
tcsetpgrp(opt_tty.fd, opt_tty.opgrp);
signal(SIGTTOU, SIG_DFL);
}
}

static void
Expand Down Expand Up @@ -603,12 +605,14 @@ init_tty(void)
die("Failed allocation for tty attributes");
tcgetattr(opt_tty.fd, opt_tty.attr);

/* process-group leader */
signal(SIGTTOU, SIG_IGN);
setpgid(getpid(), getpid());
opt_tty.opgrp = tcgetpgrp(opt_tty.fd);
tcsetpgrp(opt_tty.fd, getpid());
signal(SIGTTOU, SIG_DFL);
if (opt_pgrp) {
/* process-group leader */
setpgid(getpid(), getpid());
opt_tty.opgrp = tcgetpgrp(opt_tty.fd);
signal(SIGTTOU, SIG_IGN);
tcsetpgrp(opt_tty.fd, getpid());
signal(SIGTTOU, SIG_DFL);
}

die_callback = done_display;
}
Expand Down
9 changes: 5 additions & 4 deletions src/tig.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,10 +807,6 @@ 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 All @@ -831,6 +827,11 @@ main(int argc, const char *argv[])
die_if_failed(load_options(), "Failed to load user config.");
die_if_failed(load_git_config(), "Failed to load repo config.");

init_tty();

if (opt_pgrp)
atexit(hangup_children);

prompt_init();

/* Require a git repository unless when running in pager mode. */
Expand Down
1 change: 1 addition & 0 deletions tigrc
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ set history-size = 500 # Size of persistent history, 0 to disable
set mouse = no # Enable mouse support?
set mouse-scroll = 3 # Number of lines to scroll via the mouse
set mouse-wheel-cursor = no # Prefer moving the cursor to scrolling the view?
set pgrp = no # Make tig process-group leader

# User-defined commands
# ---------------------
Expand Down

0 comments on commit 02bfeb4

Please sign in to comment.