Skip to content

Commit

Permalink
vm: disable SIGINT handler while in factorbug
Browse files Browse the repository at this point in the history
  • Loading branch information
jckarter committed Nov 16, 2011
1 parent f27b22b commit ab9088e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 2 additions & 0 deletions vm/debug.cpp
Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down
21 changes: 18 additions & 3 deletions vm/os-unix.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions vm/os-windows.cpp
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions vm/vm.hpp
Expand Up @@ -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();

Expand Down

0 comments on commit ab9088e

Please sign in to comment.