Skip to content

Commit

Permalink
Merge pull request JuliaLang#11473 from JuliaLang/jb/signaloption
Browse files Browse the repository at this point in the history
add --handle-signals option for disabling signal handling
  • Loading branch information
JeffBezanson committed May 29, 2015
2 parents 0cde1c0 + b3544f2 commit a2430af
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
1 change: 1 addition & 0 deletions base/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ immutable JLOptions
fast_math::Int8
worker::Int8
bindto::Ptr{UInt8}
handle_signals::Int8
end

JLOptions() = unsafe_load(cglobal(:jl_options, JLOptions))
28 changes: 18 additions & 10 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ jl_options_t jl_options = { 0, // quiet
JL_OPTIONS_FAST_MATH_DEFAULT,
0, // worker
NULL, // bindto
JL_OPTIONS_HANDLE_SIGNALS_ON,
};

int jl_boot_file_loaded = 0;
Expand Down Expand Up @@ -1090,6 +1091,22 @@ void _julia_init(JL_IMAGE_SEARCH rel)
jl_current_module = jl_main_module;
jl_root_task->current_module = jl_current_module;

if (jl_options.handle_signals == JL_OPTIONS_HANDLE_SIGNALS_ON)
jl_install_default_signal_handlers();

#ifdef JL_GC_MARKSWEEP
jl_gc_enable();
#endif

if (jl_options.image_file)
jl_init_restored_modules();

if (jl_options.handle_signals == JL_OPTIONS_HANDLE_SIGNALS_ON)
jl_install_sigint_handler();
}

void jl_install_default_signal_handlers(void)
{
#ifndef _OS_WINDOWS_
signal_stack = malloc(sig_stack_size);
struct sigaction actf;
Expand Down Expand Up @@ -1187,18 +1204,9 @@ void _julia_init(JL_IMAGE_SEARCH rel)
}
SetUnhandledExceptionFilter(exception_handler);
#endif

#ifdef JL_GC_MARKSWEEP
jl_gc_enable();
#endif

if (jl_options.image_file)
jl_init_restored_modules();

jl_install_sigint_handler();
}

DLLEXPORT void jl_install_sigint_handler()
DLLEXPORT void jl_install_sigint_handler(void)
{
#ifdef _OS_WINDOWS_
SetConsoleCtrlHandler((PHANDLER_ROUTINE)sigint_handler,1);
Expand Down
7 changes: 6 additions & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1327,9 +1327,10 @@ DLLEXPORT extern volatile sig_atomic_t jl_defer_signal;

DLLEXPORT void jl_sigint_action(void);
DLLEXPORT void restore_signals(void);
DLLEXPORT void jl_install_sigint_handler();
DLLEXPORT void jl_install_sigint_handler(void);
DLLEXPORT void jl_sigatomic_begin(void);
DLLEXPORT void jl_sigatomic_end(void);
void jl_install_default_signal_handlers(void);


// tasks and exceptions -------------------------------------------------------
Expand Down Expand Up @@ -1555,6 +1556,7 @@ typedef struct {
int8_t fast_math;
int8_t worker;
const char *bindto;
int8_t handle_signals;
} jl_options_t;

extern DLLEXPORT jl_options_t jl_options;
Expand Down Expand Up @@ -1590,6 +1592,9 @@ extern DLLEXPORT jl_options_t jl_options;
#define JL_OPTIONS_FAST_MATH_OFF 2
#define JL_OPTIONS_FAST_MATH_DEFAULT 0

#define JL_OPTIONS_HANDLE_SIGNALS_ON 1
#define JL_OPTIONS_HANDLE_SIGNALS_OFF 0

// Version information
#include "julia_version.h"

Expand Down
15 changes: 13 additions & 2 deletions ui/repl.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ static const char opts[] =
" -H, --home <dir> Set location of julia executable\n"
" --startup-file={yes|no} Load ~/.juliarc.jl\n"
" -f, --no-startup Don't load ~/.juliarc (deprecated, use --startup-file=no)\n"
" -F Load ~/.juliarc (deprecated, use --startup-file=yes)\n\n"
" -F Load ~/.juliarc (deprecated, use --startup-file=yes)\n"
" --handle-signals={yes|no} Enable or disable Julia's default signal handlers\n\n"

// actions
" -e, --eval <expr> Evaluate <expr>\n"
Expand Down Expand Up @@ -110,7 +111,8 @@ void parse_opts(int *argcp, char ***argvp)
opt_inline,
opt_math_mode,
opt_worker,
opt_bind_to
opt_bind_to,
opt_handle_signals
};
static char* shortopts = "+vhqFfH:e:E:P:L:J:C:ip:Ob:";
static struct option longopts[] = {
Expand Down Expand Up @@ -143,6 +145,7 @@ void parse_opts(int *argcp, char ***argvp)
{ "depwarn", required_argument, 0, opt_depwarn },
{ "inline", required_argument, 0, opt_inline },
{ "math-mode", required_argument, 0, opt_math_mode },
{ "handle-signals", required_argument, 0, opt_handle_signals },
// hidden command line options
{ "build", required_argument, 0, 'b' },
{ "worker", no_argument, 0, opt_worker },
Expand Down Expand Up @@ -348,6 +351,14 @@ void parse_opts(int *argcp, char ***argvp)
case opt_bind_to:
jl_options.bindto = strdup(optarg);
break;
case opt_handle_signals:
if (!strcmp(optarg,"yes"))
jl_options.handle_signals = JL_OPTIONS_HANDLE_SIGNALS_ON;
else if (!strcmp(optarg,"no"))
jl_options.handle_signals = JL_OPTIONS_HANDLE_SIGNALS_OFF;
else
jl_errorf("julia: invalid argument to --handle-signals (%s)\n", optarg);
break;
default:
jl_errorf("julia: unhandled option -- %c\n"
"This is a bug, please report it.\n", c);
Expand Down

0 comments on commit a2430af

Please sign in to comment.