Skip to content

Commit

Permalink
interrupt: fix race condition with errno
Browse files Browse the repository at this point in the history
Caught by vchuravy!

It's likely that only the jl_safe_printf code to print
"force throwing a sigint" would alter errno anyways
(and thus, this fix may not be observable in practice),
but best to avoid altering `errno` in a signal handler regardless.
  • Loading branch information
vtjnash committed Jun 11, 2018
1 parent 6bb5701 commit 2c947a5
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/signals-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ static void jl_exit_thread0(int state)
void usr2_handler(int sig, siginfo_t *info, void *ctx)
{
jl_ptls_t ptls = jl_get_ptls_states();
int errno_save = errno;
sig_atomic_t request = jl_atomic_exchange(&ptls->signal_request, 0);
#if !defined(JL_DISABLE_LIBUNWIND)
if (request == 1) {
Expand Down Expand Up @@ -388,6 +389,7 @@ void usr2_handler(int sig, siginfo_t *info, void *ctx)
else if (request == 3) {
jl_call_in_ctx(ptls, jl_exit_thread0_cb, sig, ctx);
}
errno = errno_save;
}

#if defined(HAVE_TIMER)
Expand Down

0 comments on commit 2c947a5

Please sign in to comment.