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

Conversation

rolandwalker
Copy link
Contributor

Make tig the process-group leader and give it the foreground connection to the TTY. This announces to the OS "I am the interactive program taking input".

Being process-group leader allows for a simple and robust idiom for cleaning all child processes at exit time: tig can signal HUP to the entire process group (which tig can be certain that it owns). While tig doesn't intentionally keep very long running child processes, it does depend on child processes quite a bit, so this cleanup is just good practice.

As noted in test/README.adoc, this PR adds a minor issue: if the user sets stty tostop in their interactive shell, then tig's test suite will not be able to run. Actually, it will run, but then constantly stop again as output is generated. That is as intended for stty tostop: not to let multiple processes contend for writes to the terminal. The same problem would occur with tig-pick.

However

  • stty tostop is not the default setting on any Unixlike so far as I know
  • the test suite and tig-pick are edge uses

If a bug report does come in regarding tig-pick, I'm sure there's a fix with some added complexity in either tig or tig-pick.

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.

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.
@@ -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.

👍

@jonas jonas merged commit 1aad1b9 into jonas:master May 21, 2018
@jonas
Copy link
Owner

jonas commented May 21, 2018

Thanks.

@rolandwalker rolandwalker deleted the process-group-leader branch May 21, 2018 19:49
@jonas
Copy link
Owner

jonas commented May 27, 2018

This breaks my tight usage quite a bit. I often launch Tig from Vim, and now when I quit Tig, Vim is stopped and I have to run fg to get back to continue editing.

@rolandwalker
Copy link
Contributor Author

Without knowing what vim does, there might be no easy fix for that, and you have to revert.

I am very familiar with how a daemonized process works and less familiar with an interactive process.

I didn't try to look at how tig responds to SIGSTOP and SIGTSTP here (relevant to stty tostop above, and most likely to your issue as well) because those are not normal signals.

The deepest motivation is really that the hangup_children idiom, in this form, is so simple and robust. There are other less elegant ways to do the same thing.

#736 requires this, but is not important.

koutcher added a commit that referenced this pull request Jan 5, 2023
Make sure that a command still running in a view is properly terminated
when the view is closed. This is mostly visible in the pager view. That
should pretty much make #828 redundant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants