Skip to content

Commit

Permalink
also defer exit_on_sigint to end of sigatomic blocks.
Browse files Browse the repository at this point in the history
might help #11382
  • Loading branch information
JeffBezanson committed May 23, 2015
1 parent 96b511c commit 146df73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ static void jl_find_stack_bottom(void)
jl_stack_lo = jl_stack_hi - stack_size;
}

// what to do on SIGINT
DLLEXPORT void jl_sigint_action(void)
{
if (exit_on_sigint) jl_exit(0);
jl_throw(jl_interrupt_exception);
}

#ifdef _OS_WINDOWS_
static char *strsignal(int sig)
{
Expand Down Expand Up @@ -195,13 +202,12 @@ void __cdecl crt_sig_handler(int sig, int num)
break;
case SIGINT:
signal(SIGINT, (void (__cdecl *)(int))crt_sig_handler);
if (exit_on_sigint) jl_exit(0);
if (jl_defer_signal) {
jl_signal_pending = sig;
}
else {
jl_signal_pending = 0;
jl_throw(jl_interrupt_exception);
jl_sigint_action();
}
break;
default: // SIGSEGV, (SSIGTERM, IGILL)
Expand Down Expand Up @@ -326,7 +332,6 @@ volatile HANDLE hMainThread = NULL;

static BOOL WINAPI sigint_handler(DWORD wsig) //This needs winapi types to guarantee __stdcall
{
if (exit_on_sigint) jl_exit(0);
int sig;
//windows signals use different numbers from unix (raise)
switch(wsig) {
Expand All @@ -340,6 +345,7 @@ static BOOL WINAPI sigint_handler(DWORD wsig) //This needs winapi types to guara
}
else {
jl_signal_pending = 0;
if (exit_on_sigint) jl_exit(0);
if ((DWORD)-1 == SuspendThread(hMainThread)) {
//error
jl_safe_printf("error: SuspendThread failed\n");
Expand Down Expand Up @@ -477,7 +483,6 @@ void restore_signals(void)

void sigint_handler(int sig, siginfo_t *info, void *context)
{
if (exit_on_sigint) jl_exit(0);
if (jl_defer_signal) {
jl_signal_pending = sig;
}
Expand All @@ -487,7 +492,7 @@ void sigint_handler(int sig, siginfo_t *info, void *context)
sigemptyset(&sset);
sigaddset(&sset, SIGINT);
sigprocmask(SIG_UNBLOCK, &sset, NULL);
jl_throw(jl_interrupt_exception);
jl_sigint_action();
}
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1317,10 +1317,11 @@ DLLEXPORT extern volatile sig_atomic_t jl_defer_signal;
jl_defer_signal--; \
if (jl_defer_signal == 0 && jl_signal_pending != 0) { \
jl_signal_pending = 0; \
jl_throw(jl_interrupt_exception); \
jl_sigint_action(); \
} \
} while(0)

DLLEXPORT void jl_sigint_action(void);
DLLEXPORT void restore_signals(void);
DLLEXPORT void jl_install_sigint_handler();
DLLEXPORT void jl_sigatomic_begin(void);
Expand Down

0 comments on commit 146df73

Please sign in to comment.