diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2012-11-18 02:16:14 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2012-11-18 02:16:14 -0800 |
commit | c9c2fc5ee346e15e934dd72ed08774d769cfd7a1 (patch) | |
tree | 0746962ac6267fcccb25eb6950074450d7bbc47d /common.cpp | |
parent | b79854ad1aa814d9d35d76a1929b4726fa4bffa5 (diff) |
Restore terminal foreground process group on exit
Diffstat (limited to 'common.cpp')
-rw-r--r-- | common.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -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(); |