Restore terminal foreground process group on exit

Fixes https://github.com/fish-shell/fish-shell/issues/197
This commit is contained in:
ridiculousfish
2012-11-18 02:16:14 -08:00
parent b79854ad1a
commit c9c2fc5ee3
6 changed files with 45 additions and 3 deletions

View File

@@ -1917,6 +1917,9 @@ void configure_thread_assertions_for_testing(void) {
/* Notice when we've forked */
static pid_t initial_pid = 0;
/* Be able to restore the term's foreground process group */
static pid_t initial_foreground_process_group = -1;
bool is_forked_child(void) {
/* Just bail if nobody's called setup_fork_guards - e.g. fishd */
if (! initial_pid) return false;
@@ -1929,11 +1932,25 @@ bool is_forked_child(void) {
return is_child_of_fork;
}
void setup_fork_guards(void) {
void setup_fork_guards(void)
{
/* Notice when we fork by stashing our pid. This seems simpler than pthread_atfork(). */
initial_pid = getpid();
}
void save_term_foreground_process_group(void)
{
initial_foreground_process_group = tcgetpgrp(STDIN_FILENO);
}
void restore_term_foreground_process_group(void)
{
if (initial_foreground_process_group != -1)
{
tcsetpgrp(STDIN_FILENO, initial_foreground_process_group);
}
}
bool is_main_thread() {
assert (main_thread_id != 0);
return main_thread_id == pthread_self();