aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-10-26 15:22:20 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-10-26 15:22:20 -0700
commite05743d0ba1201745d40c5ebc1c8ee336ff43b64 (patch)
tree9ca3ce03c67636fa582175ca53598f3174bc9c01
parente204ced1aef4381c74787680b8653f049d125094 (diff)
Fix for errant SIGHUPs due to child fish shells messing with the term.
-rw-r--r--fish.cpp8
-rw-r--r--reader.cpp10
-rw-r--r--reader.h3
3 files changed, 19 insertions, 2 deletions
diff --git a/fish.cpp b/fish.cpp
index 24499c75..8235c529 100644
--- a/fish.cpp
+++ b/fish.cpp
@@ -389,7 +389,6 @@ int main(int argc, char **argv)
set_main_thread();
setup_fork_guards();
- save_term_foreground_process_group();
wsetlocale(LC_ALL, L"");
is_interactive_session=1;
@@ -410,6 +409,12 @@ int main(int argc, char **argv)
no_exec = 0;
}
+ /* Only save (and therefore restore) the fg process group if we are interactive. See #197, #1002 */
+ if (is_interactive_session)
+ {
+ save_term_foreground_process_group();
+ }
+
const struct config_paths_t paths = determine_config_directory_paths(argv[0]);
proc_init();
@@ -511,6 +516,7 @@ int main(int argc, char **argv)
proc_fire_event(L"PROCESS_EXIT", EVENT_EXIT, getpid(), res);
+ restore_term_mode();
restore_term_foreground_process_group();
history_destroy();
proc_destroy();
diff --git a/reader.cpp b/reader.cpp
index 228fa918..3bd40d01 100644
--- a/reader.cpp
+++ b/reader.cpp
@@ -993,10 +993,18 @@ void reader_init()
void reader_destroy()
{
- tcsetattr(0, TCSANOW, &terminal_mode_on_startup);
pthread_key_delete(generation_count_key);
}
+void restore_term_mode()
+{
+ // Restore the term mode if we own the terminal
+ // It's important we do this before restore_foreground_process_group, otherwise we won't think we own the terminal
+ if (getpid() == tcgetpgrp(STDIN_FILENO))
+ {
+ tcsetattr(STDIN_FILENO, TCSANOW, &terminal_mode_on_startup);
+ }
+}
void reader_exit(int do_exit, int forced)
{
diff --git a/reader.h b/reader.h
index 28340ad7..0d7a58f1 100644
--- a/reader.h
+++ b/reader.h
@@ -46,6 +46,9 @@ void reader_init();
*/
void reader_destroy();
+/** Restore the term mode at startup */
+void restore_term_mode();
+
/**
Returns the filename of the file currently read
*/