From 5e99a7bbbf32597cdb110225f427086e9b2cbcf9 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Tue, 15 Nov 2011 18:50:42 -0800 Subject: [PATCH] vm: disable SIGINT handler while in factorbug Fixes #410 --- vm/debug.cpp | 2 ++ vm/os-unix.cpp | 21 ++++++++++++++++++--- vm/os-windows.cpp | 10 ++++++++++ vm/vm.hpp | 2 ++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/vm/debug.cpp b/vm/debug.cpp index 3698fb1dc8..ca00580158 100755 --- a/vm/debug.cpp +++ b/vm/debug.cpp @@ -476,6 +476,7 @@ void factor_vm::factorbug_usage(bool advanced_p) static void exit_fep(factor_vm *vm) { vm->unlock_console(); + vm->handle_ctrl_c(); vm->fep_p = false; } @@ -498,6 +499,7 @@ void factor_vm::factorbug() // that pumps the console is still running concurrently. We lock a mutex so // the thread will take a break and give us exclusive access to stdin. lock_console(); + ignore_ctrl_c(); if (!fep_help_was_shown) { factorbug_usage(false); diff --git a/vm/os-unix.cpp b/vm/os-unix.cpp index 079fcb4db0..d7f4bb5ebf 100755 --- a/vm/os-unix.cpp +++ b/vm/os-unix.cpp @@ -318,7 +318,6 @@ void factor_vm::unix_init_signals() struct sigaction memory_sigaction; struct sigaction synchronous_sigaction; struct sigaction enqueue_sigaction; - struct sigaction fep_sigaction; struct sigaction sample_sigaction; struct sigaction fpe_sigaction; struct sigaction ignore_sigaction; @@ -347,8 +346,7 @@ void factor_vm::unix_init_signals() sigaction_safe(SIGINFO,&enqueue_sigaction,NULL); #endif - init_sigaction_with_handler(&fep_sigaction, fep_signal_handler); - sigaction_safe(SIGINT,&fep_sigaction,NULL); + handle_ctrl_c(); init_sigaction_with_handler(&sample_sigaction, sample_signal_handler); sigaction_safe(SIGALRM,&sample_sigaction,NULL); @@ -528,6 +526,23 @@ void factor_vm::unlock_console() pthread_mutex_unlock(&stdin_mutex); } +void factor_vm::ignore_ctrl_c() +{ + sig_t ret; + do + { + ret = signal(SIGINT, SIG_DFL); + } + while(ret == SIG_ERR && errno == EINTR); +} + +void factor_vm::handle_ctrl_c() +{ + struct sigaction fep_sigaction; + init_sigaction_with_handler(&fep_sigaction, fep_signal_handler); + sigaction_safe(SIGINT,&fep_sigaction,NULL); +} + void factor_vm::abort() { sig_t ret; diff --git a/vm/os-windows.cpp b/vm/os-windows.cpp index 5f153e2269..fc9b8c3816 100755 --- a/vm/os-windows.cpp +++ b/vm/os-windows.cpp @@ -305,6 +305,16 @@ static BOOL WINAPI ctrl_handler(DWORD dwCtrlType) } void factor_vm::open_console() +{ + handle_ctrl_c(); +} + +void factor_vm::ignore_ctrl_c() +{ + SetConsoleCtrlHandler(factor::ctrl_handler, FALSE); +} + +void factor_vm::handle_ctrl_c() { SetConsoleCtrlHandler(factor::ctrl_handler, TRUE); } diff --git a/vm/vm.hpp b/vm/vm.hpp index 7d512829d9..016bd5b7b4 100755 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -736,6 +736,8 @@ struct factor_vm static void close_console(); static void lock_console(); static void unlock_console(); + static void ignore_ctrl_c(); + static void handle_ctrl_c(); static void abort(); static void exit();