From 1247343914e96b2516f628cce5658a4d21ecf6b2 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 20 Mar 2012 09:47:32 +0100 Subject: erts: Remove unused ntbuild.erl --- erts/ntbuild.erl | 332 ------------------------------------------------------- 1 file changed, 332 deletions(-) delete mode 100644 erts/ntbuild.erl diff --git a/erts/ntbuild.erl b/erts/ntbuild.erl deleted file mode 100644 index e48be58c17..0000000000 --- a/erts/ntbuild.erl +++ /dev/null @@ -1,332 +0,0 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% -%% The contents of this file are subject to the Erlang Public License, -%% Version 1.1, (the "License"); you may not use this file except in -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved online at http://www.erlang.org/. -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. -%% -%% %CopyrightEnd% -%% -%% To be used from makefiles on the unix side executing things on the NT-side --module(ntbuild). - --export([nmake/1, omake/1, waitnode/1, restart/1, - setdir/1, run_tests/1, run_command/1]). --export([serv_nmake/2, serv_omake/2, serv_restart/0, serv_run_tests/2, - serv_run_command/1]). - -waitnode([NtNode]) -> - % First, wait for node to disappear. - case wait_disappear(NtNode, 0) of - ok -> - case wait_appear(NtNode, 0) of - ok -> - halt(0); - fail -> - halt(1) - end; - fail -> - halt(1) - end. - -% Wait for nt node to appear within 5 minutes. -wait_appear(_NtNode, 300) -> - fail; -wait_appear(NtNode, N) -> - receive after 1000 -> ok end, - case nt_node_alive(NtNode, quiet) of - no -> - wait_appear(NtNode, N+1); - yes -> - ok - end. - - - -% Waits for nt node to disappear within 3 minutes. -wait_disappear(NtNode, 300) -> - fail; -wait_disappear(NtNode, N) -> - receive after 1000 -> ok end, - case nt_node_alive(NtNode, quiet) of - yes -> - wait_disappear(NtNode, N+1); - no -> - ok - end. - -restart([NtNode]) -> - case nt_node_alive(NtNode) of - yes -> - case rpc:call(NtNode, ntbuild, serv_restart, []) of - ok -> - io:format("halt(0)~n"), - halt(); - Error -> - io:format("halt(1)~n"), - halt(1) - end; - no -> - halt(1) - end. - - -setdir([NtNode, Dir0]) -> - Dir = atom_to_list(Dir0), - case nt_node_alive(NtNode) of - yes -> - case rpc:call(NtNode, file, set_cwd, [Dir]) of - ok -> - io:format("halt(0)~n"), - halt(); - Error -> - io:format("halt(1) (Error: ~p) (~p not found) ~n", [Error, Dir]), - halt(1) - end; - no -> - halt(1) - end. - -run_tests([NtNode, Vsn0, Logdir]) -> - Vsn = atom_to_list(Vsn0), - case nt_node_alive(NtNode) of - yes -> - case rpc:call(NtNode, ntbuild, serv_run_tests, [Vsn, Logdir]) of - ok -> - io:format("halt(0)~n"), - halt(); - Error -> - io:format("RPC To Windows Node Failed: ~p~n", [Error]), - io:format("halt(1)~n"), - halt(1) - end; - no -> - halt(1) - end. - -run_command([NtNode, Cmd]) -> - case nt_node_alive(NtNode) of - yes -> - case rpc:call(NtNode, ntbuild, serv_run_command, [Cmd]) of - ok -> - io:format("halt(0)~n"), - halt(); - Error -> - io:format("RPC To Windows Node Failed: ~p~n", [Error]), - io:format("halt(1)~n"), - halt(1) - end; - no -> - halt(1) - end. - -nmake([NtNode, Path, Options]) -> -% io:format("nmake2(~w,~w)~n",[Path, Options]), - Dir=atom_to_list(Path), - Opt=atom_to_list(Options), - case nt_node_alive(NtNode) of - yes -> - case rpc:call(NtNode, ntbuild, serv_nmake, [Dir, Opt]) of - ok -> - io:format("halt(0)~n"), - halt(); - Error -> - io:format("Error: ~n", [Error]), - halt(1) - end; - no -> - halt(1) - end. - -omake([NtNode, Path, Options]) -> - Dir=atom_to_list(Path), - Opt=atom_to_list(Options), - case nt_node_alive(NtNode) of - yes -> - case rpc:call(NtNode, ntbuild, serv_omake, [Dir, Opt]) of - ok -> - io:format("halt(0)~n"), - halt(); - Error -> - io:format("RPC To Windows Node Failed: ~p~n", [Error]), - io:format("~p ~p~n", [Dir, Opt]), - io:format("halt(1)~n"), - halt(1) - end; - no -> - halt(1) - end. - - - - - -nt_node_alive(NtNode) -> - case net:ping(NtNode) of - pong -> - yes; - pang -> - io:format("The NT node (~p) is not up. ~n",[NtNode]), - no - end. - -nt_node_alive(NtNode, quiet) -> - case net:ping(NtNode) of - pong -> - yes; - pang -> - no - end. - - - -%%% -%%% The 'serv_' functions. Theese are the routines run on the WinNT node. -%%% - -%%----------------------- -%% serv_run_tests() -%% Runs the tests. -serv_run_tests(Vsn, Logdir) -> - {ok, Cwd}=file:get_cwd(), - io:format("serv_run_tests ~p ~p ~n", [Vsn, Logdir]), - Cmd0= "set central_log_dir=" ++ Logdir, - Erl = "C:/progra~1/erl"++Vsn++"/bin/erl", - Cmd1 = Erl++" -sname a -setcookie a -noshell -noinput -s ts install -s ts run -s ts save -s erlang halt", -%% Dir = "C:/temp/test_suite/test_server", - Cmd= Cmd0 ++ "/r/n" ++ Cmd1, - Dir = "C:/temp/test_server/p7a/test_server", - file:set_cwd(Dir), - Res=run_make_bat(Dir, Cmd), - file:set_cwd(Cwd), - Res. - -%%----------------------- -%% serv_run_command() -%% Runs a command. -serv_run_command(Cmd) -> - {ok, Cwd}=file:get_cwd(), - Res=run_make_bat("", Cmd), - file:set_cwd(Cwd), - Res. - -%%----------------------- -%% serv_restart() -%% Reboots the NT machine. -serv_restart() -> - Exe="\\erts\\install_nt\\reboot.exe", - open_port({spawn, Exe}, [stream, eof, in]), - ok. - - -%%----------------------- -%% serv_nmake(Path, Options) -%% Runs `nmake' in the given directory. -%% Result: ok | error -serv_nmake(Path, Options) -> - {ok, Cwd}=file:get_cwd(), - Command="nmake -e -f Makefile.win32 " ++ Options ++ " 2>&1", - Res=run_make_bat(Path, Command), - file:set_cwd(Cwd), - Res. - -%%----------------------- -%% serv_omake(Path, Options) -%% Runs `omake' in the given directory. -%% Result: ok | error -serv_omake(Path, Options) -> - {ok, Cwd}=file:get_cwd(), - Command="omake -W -E -EN -f Makefile.win32 " ++ Options ++ " 2>&1", - Res=run_make_bat(Path, Command), - file:set_cwd(Cwd), - Res. - - -read_output(Port, SoFar) -> -% io:format("(read_output)~n"), - case get_data_from_port(Port) of - eof -> - io:format("*** eof ***~n"), - io:format("Never reached a real message"), - halt(1); - {ok, Data} -> - case print_line([SoFar|Data]) of - {ok, Rest} -> - read_output(Port, Rest); - {done, Res} -> - Res - end - end. - -print_line(Data) -> - print_line(Data, []). - -print_line([], Acc) -> - {ok, lists:reverse(Acc)}; -print_line([$*,$o,$k,$*|Rest], _Acc) -> - io:format("*ok*~n"), - {done, ok}; -print_line([$*,$e,$r,$r,$o,$r|Rest], _Acc) -> - io:format("*error*~n"), - {done, error}; -print_line([$\r,$\n|Rest], Acc) -> - io:format("~s~n", [lists:reverse(Acc)]), - print_line(Rest, []); -print_line([Chr|Rest], Acc) -> - print_line(Rest, [Chr|Acc]). - -get_data_from_port(Port) -> - receive - {Port, {data, Bytes}} -> - {ok, Bytes}; - {Port, eof} -> - unlink(Port), - exit(Port, die), - eof; - Other -> - io:format("Strange message received: ~p~n", [Other]), - get_data_from_port(Port) - end. - - -run_make_bat(Dir, Make) -> - {Name, Exe, Script}=create_make_script(Dir, Make), - io:format("Exe:~p Cwd:~p Script:~p ~n",[Exe, Dir, Script]), - case file:write_file(Name, Script) of - ok -> - case catch open_port({spawn, Exe}, [stderr_to_stdout, stream, hide, - eof, in]) of - Port when port(Port) -> - read_output(Port, []); - Other -> - io:format("Error, open_port failed: ~p~n", [Other]), - {open_port, Other, Exe} - end; - Error -> - {write_file, Error, Name} - end. - -create_make_script(Dir, Make) when atom(Make) -> - create_make_script(Dir, atom_to_list(Make)); -create_make_script(Dir, Make) -> - {"run_make_bs.bat", - "run_make_bs 2>&1", - ["@echo off\r\n", - "@cd ", Dir, "\r\n", - Make++"\r\n", - "if errorlevel 1 echo *run_make_bs error*\r\n", - "if not errorlevel 1 echo *ok*\r\n"]}. - - - - - -- cgit v1.2.3 From 5b740336b0d7d0aec7c4df3b3e5c968ec0456766 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 20 Mar 2012 09:49:09 +0100 Subject: erts: Implement erl_halt --- erts/emulator/beam/erl_init.c | 48 ++++++++++------ erts/emulator/beam/erl_process.c | 118 ++++++++++++++++++++++++++++++++++++--- erts/emulator/beam/erl_process.h | 6 +- erts/emulator/beam/global.h | 5 +- erts/emulator/beam/io.c | 7 +++ erts/emulator/beam/sys.h | 4 +- 6 files changed, 160 insertions(+), 28 deletions(-) diff --git a/erts/emulator/beam/erl_init.c b/erts/emulator/beam/erl_init.c index 717315d8bd..d866a1fe3f 100644 --- a/erts/emulator/beam/erl_init.c +++ b/erts/emulator/beam/erl_init.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1997-2011. All Rights Reserved. + * Copyright Ericsson AB 1997-2012. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -1510,7 +1510,7 @@ __decl_noreturn void erts_thr_fatal_error(int err, char *what) #endif static void -system_cleanup(int exit_code) +system_cleanup(int flush_async) { /* * Make sure only one thread exits the runtime system. @@ -1542,7 +1542,7 @@ system_cleanup(int exit_code) * (in threaded non smp case). */ - if (exit_code != 0 + if (!flush_async || !erts_initialized #if defined(USE_THREADS) && !defined(ERTS_SMP) || !erts_equal_tids(main_thread, erts_thr_self()) @@ -1632,14 +1632,12 @@ __decl_noreturn void erl_exit0(char *file, int line, int n, char *fmt,...) exit(an); } -__decl_noreturn void erl_exit(int n, char *fmt,...) +static __decl_noreturn void __noreturn +erl_exit_vv(int n, int flush_async, char *fmt, va_list args1, va_list args2) { unsigned int an; - va_list args; - va_start(args, fmt); - - system_cleanup(n); + system_cleanup(flush_async); save_statistics(); @@ -1649,18 +1647,13 @@ __decl_noreturn void erl_exit(int n, char *fmt,...) erts_mtrace_exit((Uint32) an); /* Produce an Erlang core dump if error */ - if (n > 0 && erts_initialized && - (erts_no_crash_dump == 0 || n == ERTS_DUMP_EXIT)) { - erl_crash_dump_v((char*) NULL, 0, fmt, args); + if (((n > 0 && erts_no_crash_dump == 0) || n == ERTS_DUMP_EXIT) + && erts_initialized) { + erl_crash_dump_v((char*) NULL, 0, fmt, args1); } - /* need to reinitialize va_args thing */ - va_end(args); - va_start(args, fmt); - if (fmt != NULL && *fmt != '\0') - erl_error(fmt, args); /* Print error message. */ - va_end(args); + erl_error(fmt, args2); /* Print error message. */ sys_tty_reset(n); if (n == ERTS_INTR_EXIT) @@ -1672,3 +1665,24 @@ __decl_noreturn void erl_exit(int n, char *fmt,...) exit(an); } +/* Exit without flushing async threads */ +__decl_noreturn void __noreturn erl_exit(int n, char *fmt, ...) +{ + va_list args1, args2; + va_start(args1, fmt); + va_start(args2, fmt); + erl_exit_vv(n, 0, fmt, args1, args2); + va_end(args2); + va_end(args1); +} + +/* Exit after flushing async threads */ +__decl_noreturn void __noreturn erl_exit_flush_async(int n, char *fmt, ...) +{ + va_list args1, args2; + va_start(args1, fmt); + va_start(args2, fmt); + erl_exit_vv(n, 1, fmt, args1, args2); + va_end(args2); + va_end(args1); +} diff --git a/erts/emulator/beam/erl_process.c b/erts/emulator/beam/erl_process.c index 138acfeb2c..45f6dc800c 100644 --- a/erts/emulator/beam/erl_process.c +++ b/erts/emulator/beam/erl_process.c @@ -104,6 +104,9 @@ do { \ #define ERTS_EMPTY_RUNQ(RQ) \ ((RQ)->len == 0 && (RQ)->misc.start == NULL) +#define ERTS_EMPTY_RUNQ_PORTS(RQ) \ + ((RQ)->ports.info.len == 0 && (RQ)->misc.start == NULL) + extern BeamInstr beam_apply[]; extern BeamInstr beam_exit[]; extern BeamInstr beam_continue_exit[]; @@ -366,6 +369,9 @@ dbg_chk_aux_work_val(erts_aint32_t value) #ifdef ERTS_SMP_SCHEDULERS_NEED_TO_CHECK_CHILDREN valid |= ERTS_SSI_AUX_WORK_CHECK_CHILDREN; #endif +#ifdef ERTS_SSI_AUX_WORK_REAP_PORTS + valid |= ERTS_SSI_AUX_WORK_REAP_PORTS; +#endif if (~valid & value) erl_exit(ERTS_ABORT_EXIT, @@ -861,8 +867,6 @@ set_aux_work_flags_wakeup_nob(ErtsSchedulerSleepInfo *ssi, } } -#if 0 /* Currently not used */ - static ERTS_INLINE void set_aux_work_flags_wakeup_relb(ErtsSchedulerSleepInfo *ssi, erts_aint32_t flgs) @@ -882,8 +886,6 @@ set_aux_work_flags_wakeup_relb(ErtsSchedulerSleepInfo *ssi, } } -#endif - static ERTS_INLINE erts_aint32_t set_aux_work_flags(ErtsSchedulerSleepInfo *ssi, erts_aint32_t flgs) { @@ -1351,6 +1353,65 @@ handle_check_children(ErtsAuxWorkData *awdp, erts_aint32_t aux_work) #endif +static void +notify_reap_ports_relb(void) +{ + int i; + for (i = 0; i < erts_no_schedulers; i++) { + set_aux_work_flags_wakeup_relb(ERTS_SCHED_SLEEP_INFO_IX(i), + ERTS_SSI_AUX_WORK_REAP_PORTS); + } +} + +erts_smp_atomic32_t erts_halt_progress; +int erts_halt_code; + +static ERTS_INLINE erts_aint32_t +handle_reap_ports(ErtsAuxWorkData *awdp, erts_aint32_t aux_work) +{ + unset_aux_work_flags(awdp->ssi, ERTS_SSI_AUX_WORK_REAP_PORTS); + awdp->esdp->run_queue->halt_in_progress = 1; + if (erts_smp_atomic32_dec_read_acqb(&erts_halt_progress) == 0) { + int i; + erts_smp_atomic32_set_nob(&erts_halt_progress, 1); + for (i = 0; i < erts_max_ports; i++) { + Port *prt = &erts_port[i]; + erts_smp_port_state_lock(prt); + if ((prt->status & (ERTS_PORT_SFLGS_INVALID_DRIVER_LOOKUP + | ERTS_PORT_SFLG_HALT))) { + erts_smp_port_state_unlock(prt); + continue; + } + /* We need to set the halt flag - get the port lock */ +#ifdef ERTS_SMP + erts_smp_atomic_inc_nob(&prt->refc); +#endif + erts_smp_port_state_unlock(prt); +#ifdef ERTS_SMP + erts_smp_mtx_lock(prt->lock); +#endif + if ((prt->status & (ERTS_PORT_SFLGS_INVALID_DRIVER_LOOKUP + | ERTS_PORT_SFLG_HALT))) { + erts_port_release(prt); + continue; + } + erts_port_status_bor_set(prt, ERTS_PORT_SFLG_HALT); + erts_smp_atomic32_inc_nob(&erts_halt_progress); + if (prt->status & (ERTS_PORT_SFLG_EXITING + | ERTS_PORT_SFLG_CLOSING)) { + erts_port_release(prt); + continue; + } + erts_do_exit_port(prt, prt->id, am_killed); + erts_port_release(prt); + } + if (erts_smp_atomic32_dec_read_nob(&erts_halt_progress) == 0) { + erl_exit_flush_async(erts_halt_code, ""); + } + } + return aux_work & ~ERTS_SSI_AUX_WORK_REAP_PORTS; +} + #if HAVE_ERTS_MSEG static ERTS_INLINE erts_aint32_t @@ -1451,6 +1512,9 @@ handle_aux_work(ErtsAuxWorkData *awdp, erts_aint32_t orig_aux_work) handle_mseg_cache_check); #endif + HANDLE_AUX_WORK(ERTS_SSI_AUX_WORK_REAP_PORTS, + handle_reap_ports); + ERTS_DBG_CHK_AUX_WORK_VAL(aux_work); return aux_work; @@ -2716,6 +2780,9 @@ try_steal_task_from_victim(ErtsRunQueue *rq, int *rq_lockedp, ErtsRunQueue *vrq) ERTS_SMP_LC_CHK_RUNQ_LOCK(rq, *rq_lockedp); ERTS_SMP_LC_CHK_RUNQ_LOCK(vrq, vrq_locked); + if (rq->halt_in_progress) + goto try_steal_port; + /* * Check for a runnable process to steal... */ @@ -2802,6 +2869,8 @@ try_steal_task_from_victim(ErtsRunQueue *rq, int *rq_lockedp, ErtsRunQueue *vrq) vrq_locked = 1; } + try_steal_port: + ERTS_SMP_LC_CHK_RUNQ_LOCK(rq, *rq_lockedp); ERTS_SMP_LC_CHK_RUNQ_LOCK(vrq, vrq_locked); @@ -2917,7 +2986,8 @@ try_steal_task(ErtsRunQueue *rq) erts_smp_runq_lock(rq); if (!res) - res = !ERTS_EMPTY_RUNQ(rq); + res = rq->halt_in_progress ? + !ERTS_EMPTY_RUNQ_PORTS(rq) : !ERTS_EMPTY_RUNQ(rq); return res; } @@ -3583,6 +3653,7 @@ erts_init_scheduling(int no_schedulers, int no_schedulers_online) rq->len = 0; rq->wakeup_other = 0; rq->wakeup_other_reds = 0; + rq->halt_in_progress = 0; rq->procs.len = 0; rq->procs.pending_exiters = NULL; @@ -3777,6 +3848,9 @@ erts_init_scheduling(int no_schedulers, int no_schedulers_online) ERTS_VERIFY_UNUSED_TEMP_ALLOC(NULL); #endif #endif + + erts_smp_atomic32_init_relb(&erts_halt_progress, -1); + erts_halt_code = 0; } ErtsRunQueue * @@ -6343,7 +6417,9 @@ Process *schedule(Process *p, int calls) ASSERT(rq->len == rq->procs.len + rq->ports.info.len); - if (rq->len == 0 && !rq->misc.start) { + if ((rq->len == 0 && !rq->misc.start) + || (rq->halt_in_progress + && rq->ports.info.len == 0 && !rq->misc.start)) { #ifdef ERTS_SMP @@ -6441,7 +6517,8 @@ Process *schedule(Process *p, int calls) if (rq->ports.info.len) { int have_outstanding_io; have_outstanding_io = erts_port_task_execute(rq, &esdp->current_port); - if (have_outstanding_io && fcalls > 2*input_reductions) { + if ((have_outstanding_io && fcalls > 2*input_reductions) + || rq->halt_in_progress) { /* * If we have performed more than 2*INPUT_REDUCTIONS since * last call to erl_sys_schedule() and we still haven't @@ -9867,3 +9944,30 @@ debug_processes_assert_error(char* expr, char* file, int line) /* *\ * End of the processes/0 BIF implementation. * \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * A nice system halt closing all open port goes as follows: + * 1) This function schedules the aux work ERTS_SSI_AUX_WORK_REAP_PORTS + * on all schedulers, then schedules itself out. + * 2) All shedulers detect this and set the flag halt_in_progress + * on their run queue. The last scheduler sets all non-closed ports + * ERTS_PORT_SFLG_HALT. Global atomic erts_halt_progress is used + * as refcount to determine which is last. + * 3) While the run ques has flag halt_in_progress no processes + * will be scheduled, only ports. + * 4) When the last port closes that scheduler calls erlang:halt/1. + * The same global atomic is used as refcount. + * + * A BIF that calls this should make sure to schedule out to never come back: + * erl_halt((int)(- code)); + * ERTS_BIF_YIELD1(bif_export[BIF_erlang_halt_1], BIF_P, NIL); + */ +void erl_halt(int code) +{ + if (-1 == erts_smp_atomic32_cmpxchg_acqb(&erts_halt_progress, + erts_no_schedulers, + -1)) { + erts_halt_code = code; + notify_reap_ports_relb(); + } +} diff --git a/erts/emulator/beam/erl_process.h b/erts/emulator/beam/erl_process.h index c23810f15a..d671638ce8 100644 --- a/erts/emulator/beam/erl_process.h +++ b/erts/emulator/beam/erl_process.h @@ -264,6 +264,7 @@ typedef enum { #define ERTS_SSI_AUX_WORK_CHECK_CHILDREN (((erts_aint32_t) 1) << 8) #define ERTS_SSI_AUX_WORK_SET_TMO (((erts_aint32_t) 1) << 9) #define ERTS_SSI_AUX_WORK_MSEG_CACHE_CHECK (((erts_aint32_t) 1) << 10) +#define ERTS_SSI_AUX_WORK_REAP_PORTS (((erts_aint32_t) 1) << 11) typedef struct ErtsSchedulerSleepInfo_ ErtsSchedulerSleepInfo; @@ -341,6 +342,7 @@ struct ErtsRunQueue_ { int len; int wakeup_other; int wakeup_other_reds; + int halt_in_progress; struct { int len; @@ -1659,4 +1661,6 @@ erts_sched_poke(ErtsSchedulerSleepInfo *ssi) #endif - +void erl_halt(int code); +extern erts_smp_atomic32_t erts_halt_progress; +extern int erts_halt_code; diff --git a/erts/emulator/beam/global.h b/erts/emulator/beam/global.h index f1335f600d..34eb984925 100644 --- a/erts/emulator/beam/global.h +++ b/erts/emulator/beam/global.h @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1996-2011. All Rights Reserved. + * Copyright Ericsson AB 1996-2012. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -806,6 +806,8 @@ do { \ /* Port uses port specific locking (opposed to driver specific locking) */ #define ERTS_PORT_SFLG_PORT_SPECIFIC_LOCK ((Uint32) (1 << 13)) #define ERTS_PORT_SFLG_INVALID ((Uint32) (1 << 14)) +/* Last port to terminate halts the emulator */ +#define ERTS_PORT_SFLG_HALT ((Uint32) (1 << 15)) #ifdef DEBUG /* Only debug: make sure all flags aren't cleared unintentionally */ #define ERTS_PORT_SFLG_PORT_DEBUG ((Uint32) (1 << 31)) @@ -900,6 +902,7 @@ void loaded(int, void *); __decl_noreturn void __noreturn erl_exit(int n, char*, ...); __decl_noreturn void __noreturn erl_exit0(char *, int, int n, char*, ...); +__decl_noreturn void __noreturn erl_exit_flush_async(int n, char*, ...); void erl_error(char*, va_list); #define ERL_EXIT0(n,f) erl_exit0(__FILE__, __LINE__, n, f) diff --git a/erts/emulator/beam/io.c b/erts/emulator/beam/io.c index b23b1f628d..591eb834e6 100644 --- a/erts/emulator/beam/io.c +++ b/erts/emulator/beam/io.c @@ -1837,6 +1837,7 @@ terminate_port(Port *prt) Eterm send_closed_port_id; Eterm connected_id = NIL /* Initialize to silence compiler */; erts_driver_t *drv; + int halt; ERTS_SMP_CHK_NO_PROC_LOCKS; ERTS_SMP_LC_ASSERT(erts_lc_is_port_locked(prt)); @@ -1844,6 +1845,8 @@ terminate_port(Port *prt) ASSERT(!prt->nlinks); ASSERT(!prt->monitors); + /* prt->status may be altered by kill_port()below */ + halt = (prt->status & ERTS_PORT_SFLG_HALT) != 0; if (prt->status & ERTS_PORT_SFLG_SEND_CLOSED) { erts_port_status_band_set(prt, ~ERTS_PORT_SFLG_SEND_CLOSED); send_closed_port_id = prt->id; @@ -1895,6 +1898,10 @@ terminate_port(Port *prt) * We don't want to send the closed message until after the * port has been removed from the port table (in kill_port()). */ + if (halt && (erts_smp_atomic32_dec_read_nob(&erts_halt_progress) == 0)) { + erts_smp_port_unlock(prt); /* We will exit and never return */ + erl_exit_flush_async(erts_halt_code, ""); + } if (is_internal_port(send_closed_port_id)) deliver_result(send_closed_port_id, connected_id, am_closed); diff --git a/erts/emulator/beam/sys.h b/erts/emulator/beam/sys.h index eb6f2f8516..7b2bb81f62 100644 --- a/erts/emulator/beam/sys.h +++ b/erts/emulator/beam/sys.h @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1996-2011. All Rights Reserved. + * Copyright Ericsson AB 1996-2012. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -511,7 +511,7 @@ __decl_noreturn void __noreturn erl_exit(int n, char*, ...); /* Some special erl_exit() codes: */ #define ERTS_INTR_EXIT INT_MIN /* called from signal handler */ #define ERTS_ABORT_EXIT (INT_MIN + 1) /* no crash dump; only abort() */ -#define ERTS_DUMP_EXIT (127) /* crash dump; then exit() */ +#define ERTS_DUMP_EXIT (INT_MIN + 2) /* crash dump; then exit() */ Eterm erts_check_io_info(void *p); -- cgit v1.2.3 From b9f091205a4871f248f17a733c569d5921b6d329 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Fri, 9 Mar 2012 16:12:16 +0100 Subject: erts: Remove forgotten and unused function erl_exit0 --- erts/emulator/beam/erl_init.c | 47 ------------------------------------------- erts/emulator/beam/global.h | 6 ------ 2 files changed, 53 deletions(-) diff --git a/erts/emulator/beam/erl_init.c b/erts/emulator/beam/erl_init.c index d866a1fe3f..ca4385dd3a 100644 --- a/erts/emulator/beam/erl_init.c +++ b/erts/emulator/beam/erl_init.c @@ -1585,53 +1585,6 @@ system_cleanup(int flush_async) erts_exit_flush_async(); } -/* - * Common exit function, all exits from the system go through here. - * n <= 0 -> normal exit with status n; - * n = 127 -> Erlang crash dump produced, exit with status 1; - * other positive n -> Erlang crash dump and core dump produced. - */ - -__decl_noreturn void erl_exit0(char *file, int line, int n, char *fmt,...) -{ - unsigned int an; - va_list args; - - va_start(args, fmt); - - system_cleanup(n); - - save_statistics(); - - an = abs(n); - - if (erts_mtrace_enabled) - erts_mtrace_exit((Uint32) an); - - /* Produce an Erlang core dump if error */ - if (n > 0 && erts_initialized && - (erts_no_crash_dump == 0 || n == ERTS_DUMP_EXIT)) { - erl_crash_dump_v(file, line, fmt, args); - } - - /* need to reinitialize va_args thing */ - va_end(args); - va_start(args, fmt); - - if (fmt != NULL && *fmt != '\0') - erl_error(fmt, args); /* Print error message. */ - va_end(args); - sys_tty_reset(n); - - if (n == ERTS_INTR_EXIT) - exit(0); - else if (n == 127) - ERTS_EXIT_AFTER_DUMP(1); - else if (n > 0 || n == ERTS_ABORT_EXIT) - abort(); - exit(an); -} - static __decl_noreturn void __noreturn erl_exit_vv(int n, int flush_async, char *fmt, va_list args1, va_list args2) { diff --git a/erts/emulator/beam/global.h b/erts/emulator/beam/global.h index 34eb984925..97d7f0e904 100644 --- a/erts/emulator/beam/global.h +++ b/erts/emulator/beam/global.h @@ -901,15 +901,9 @@ void loaded(int, void *); /* config.c */ __decl_noreturn void __noreturn erl_exit(int n, char*, ...); -__decl_noreturn void __noreturn erl_exit0(char *, int, int n, char*, ...); __decl_noreturn void __noreturn erl_exit_flush_async(int n, char*, ...); void erl_error(char*, va_list); -#define ERL_EXIT0(n,f) erl_exit0(__FILE__, __LINE__, n, f) -#define ERL_EXIT1(n,f,a) erl_exit0(__FILE__, __LINE__, n, f, a) -#define ERL_EXIT2(n,f,a,b) erl_exit0(__FILE__, __LINE__, n, f, a, b) -#define ERL_EXIT3(n,f,a,b,c) erl_exit0(__FILE__, __LINE__, n, f, a, b, c) - /* copy.c */ void init_copy(void); Eterm copy_object(Eterm, Process*); -- cgit v1.2.3 From 3a10d2e251e5490c05b32ca9c18165e9d1a055d9 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Mon, 19 Mar 2012 10:49:39 +0100 Subject: erts: Make erlang:halt/0,1 close ports and flush async threads --- erts/emulator/beam/bif.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/erts/emulator/beam/bif.c b/erts/emulator/beam/bif.c index f8305944a4..148817bc7c 100644 --- a/erts/emulator/beam/bif.c +++ b/erts/emulator/beam/bif.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1996-2011. All Rights Reserved. + * Copyright Ericsson AB 1996-2012. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -3666,9 +3666,8 @@ BIF_RETTYPE display_nl_0(BIF_ALIST_0) BIF_RETTYPE halt_0(BIF_ALIST_0) { VERBOSE(DEBUG_SYSTEM,("System halted by BIF halt/0\n")); - erts_smp_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN); - erl_exit(0, ""); - return NIL; /* Pedantic (lint does not know about erl_exit) */ + erl_halt(0); + ERTS_BIF_YIELD1(bif_export[BIF_halt_1], BIF_P, am_undefined); } /**********************************************************************/ @@ -3685,12 +3684,12 @@ BIF_RETTYPE halt_1(BIF_ALIST_1) if (is_small(BIF_ARG_1) && (code = signed_val(BIF_ARG_1)) >= 0) { VERBOSE(DEBUG_SYSTEM,("System halted by BIF halt(%d)\n", code)); - erts_smp_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN); - erl_exit(-code, ""); - } else if (is_string(BIF_ARG_1) || BIF_ARG_1 == NIL) { - if ((i = intlist_to_buf(BIF_ARG_1, msg, MSG_SIZE-1)) < 0) { + erl_halt((int)(- code)); + ERTS_BIF_YIELD1(bif_export[BIF_halt_1], BIF_P, am_undefined); + } + else if (is_string(BIF_ARG_1) || BIF_ARG_1 == NIL) { + if ((i = intlist_to_buf(BIF_ARG_1, halt_msg, HALT_MSG_SIZE-1)) < 0) goto error; - } msg[i] = '\0'; VERBOSE(DEBUG_SYSTEM,("System halted by BIF halt(%s)\n", msg)); erts_smp_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN); -- cgit v1.2.3 From 83d38d0dda488ecb7090f3070a5b2569be5a555e Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Thu, 15 Mar 2012 11:22:59 +0100 Subject: stdlib: Stop working around erlang:halt not flushing --- lib/stdlib/src/erl_compile.erl | 14 ++------------ lib/stdlib/src/escript.erl | 14 ++------------ 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/lib/stdlib/src/erl_compile.erl b/lib/stdlib/src/erl_compile.erl index ff032b129c..81bec21a3f 100644 --- a/lib/stdlib/src/erl_compile.erl +++ b/lib/stdlib/src/erl_compile.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2011. All Rights Reserved. +%% Copyright Ericsson AB 1997-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -57,17 +57,7 @@ compile_cmdline(List) -> end. my_halt(Reason) -> - case process_info(group_leader(), status) of - {_,waiting} -> - %% Now all output data is down in the driver. - %% Give the driver some extra time before halting. - receive after 1 -> ok end, - halt(Reason); - _ -> - %% Probably still processing I/O requests. - erlang:yield(), - my_halt(Reason) - end. + erlang:halt(Reason). %% Run the the compiler in a separate process, trapping EXITs. diff --git a/lib/stdlib/src/escript.erl b/lib/stdlib/src/escript.erl index ad49d89908..27e70ac4d4 100644 --- a/lib/stdlib/src/escript.erl +++ b/lib/stdlib/src/escript.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2007-2011. All Rights Reserved. +%% Copyright Ericsson AB 2007-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -848,17 +848,7 @@ fatal(Str) -> throw(Str). my_halt(Reason) -> - case process_info(group_leader(), status) of - {_,waiting} -> - %% Now all output data is down in the driver. - %% Give the driver some extra time before halting. - receive after 1 -> ok end, - halt(Reason); - _ -> - %% Probably still processing I/O requests. - erlang:yield(), - my_halt(Reason) - end. + erlang:halt(Reason). hidden_apply(App, M, F, Args) -> try -- cgit v1.2.3 From b80ee2bbf4c2c28ceeb3e561fddc9020c686071f Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Mon, 19 Mar 2012 10:55:31 +0100 Subject: erts: Implement erlang:halt/2 --- erts/emulator/beam/bif.c | 102 +++++++++++++++++++++++++++++++++++----- erts/emulator/beam/bif.tab | 4 +- lib/hipe/cerl/erl_bif_types.erl | 8 +++- lib/stdlib/src/erl_internal.erl | 3 +- 4 files changed, 102 insertions(+), 15 deletions(-) diff --git a/erts/emulator/beam/bif.c b/erts/emulator/beam/bif.c index 148817bc7c..ebdca87f4a 100644 --- a/erts/emulator/beam/bif.c +++ b/erts/emulator/beam/bif.c @@ -3665,42 +3665,122 @@ BIF_RETTYPE display_nl_0(BIF_ALIST_0) /* ARGSUSED */ BIF_RETTYPE halt_0(BIF_ALIST_0) { - VERBOSE(DEBUG_SYSTEM,("System halted by BIF halt/0\n")); + VERBOSE(DEBUG_SYSTEM,("System halted by BIF halt()\n")); erl_halt(0); ERTS_BIF_YIELD1(bif_export[BIF_halt_1], BIF_P, am_undefined); } /**********************************************************************/ -#define MSG_SIZE 200 +#define HALT_MSG_SIZE 200 +static char halt_msg[HALT_MSG_SIZE]; /* stop the system with exit code */ /* ARGSUSED */ BIF_RETTYPE halt_1(BIF_ALIST_1) { Sint code; - static char msg[MSG_SIZE]; - int i; if (is_small(BIF_ARG_1) && (code = signed_val(BIF_ARG_1)) >= 0) { - VERBOSE(DEBUG_SYSTEM,("System halted by BIF halt(%d)\n", code)); + VERBOSE(DEBUG_SYSTEM,("System halted by BIF halt(%T)\n", BIF_ARG_1)); erl_halt((int)(- code)); ERTS_BIF_YIELD1(bif_export[BIF_halt_1], BIF_P, am_undefined); } + else if (ERTS_IS_ATOM_STR("abort", BIF_ARG_1)) { + VERBOSE(DEBUG_SYSTEM,("System halted by BIF halt(%T)\n", BIF_ARG_1)); + erts_smp_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN); + erl_exit(ERTS_ABORT_EXIT, ""); + } else if (is_string(BIF_ARG_1) || BIF_ARG_1 == NIL) { - if ((i = intlist_to_buf(BIF_ARG_1, halt_msg, HALT_MSG_SIZE-1)) < 0) + int i; + + if ((i = intlist_to_buf(BIF_ARG_1, halt_msg, HALT_MSG_SIZE-1)) < 0) { goto error; - msg[i] = '\0'; - VERBOSE(DEBUG_SYSTEM,("System halted by BIF halt(%s)\n", msg)); + } + halt_msg[i] = '\0'; + VERBOSE(DEBUG_SYSTEM,("System halted by BIF halt(%T)\n", BIF_ARG_1)); erts_smp_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN); - erl_exit(ERTS_DUMP_EXIT, "%s\n", msg); - } else { - error: + erl_exit(ERTS_DUMP_EXIT, "%s\n", halt_msg); + } + else + goto error; + return NIL; /* Pedantic (lint does not know about erl_exit) */ + error: BIF_ERROR(BIF_P, BADARG); +} + +/**********************************************************************/ + +/* stop the system with exit code and flags */ +/* ARGSUSED */ +BIF_RETTYPE halt_2(BIF_ALIST_2) +{ + Sint code; + Eterm optlist = BIF_ARG_2; + int flush = 0; + + for (optlist = BIF_ARG_2; + is_list(optlist); + optlist = CDR(list_val(optlist))) { + Eterm *tp, opt = CAR(list_val(optlist)); + if (is_not_tuple(opt)) + goto error; + tp = tuple_val(opt); + if (tp[0] != make_arityval(2)) + goto error; + if (tp[1] == am_flush) { + if (tp[2] == am_true) + flush = 1; + else if (tp[2] == am_false) + flush = 0; + else + goto error; + } + else + goto error; } + if (is_not_nil(optlist)) + goto error; + + if (is_small(BIF_ARG_1) && (code = signed_val(BIF_ARG_1)) >= 0) { + VERBOSE(DEBUG_SYSTEM, + ("System halted by BIF halt(%T, %T)\n", BIF_ARG_1, BIF_ARG_2)); + if (flush) { + erl_halt((int)(- code)); + ERTS_BIF_YIELD1(bif_export[BIF_halt_1], BIF_P, am_undefined); + } + else { + erts_smp_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN); + erl_exit((int)(- code), ""); + } + } + else if (ERTS_IS_ATOM_STR("abort", BIF_ARG_1)) { + VERBOSE(DEBUG_SYSTEM, + ("System halted by BIF halt(%T, %T)\n", BIF_ARG_1, BIF_ARG_2)); + erts_smp_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN); + erl_exit(ERTS_ABORT_EXIT, ""); + } + else if (is_string(BIF_ARG_1) || BIF_ARG_1 == NIL) { + int i; + + if ((i = intlist_to_buf(BIF_ARG_1, halt_msg, HALT_MSG_SIZE-1)) < 0) { + goto error; + } + halt_msg[i] = '\0'; + VERBOSE(DEBUG_SYSTEM, + ("System halted by BIF halt(%T, %T)\n", BIF_ARG_1, BIF_ARG_2)); + erts_smp_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN); + erl_exit(ERTS_DUMP_EXIT, "%s\n", halt_msg); + } + else + goto error; return NIL; /* Pedantic (lint does not know about erl_exit) */ + error: + BIF_ERROR(BIF_P, BADARG); } +/**********************************************************************/ + BIF_RETTYPE function_exported_3(BIF_ALIST_3) { if (is_not_atom(BIF_ARG_1) || diff --git a/erts/emulator/beam/bif.tab b/erts/emulator/beam/bif.tab index 8cc568b16c..007c884a6a 100644 --- a/erts/emulator/beam/bif.tab +++ b/erts/emulator/beam/bif.tab @@ -1,7 +1,7 @@ # # %CopyrightBegin% # -# Copyright Ericsson AB 1996-2011. All Rights Reserved. +# Copyright Ericsson AB 1996-2012. All Rights Reserved. # # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in @@ -115,6 +115,8 @@ bif erlang:halt/0 bif 'erl.lang.system':halt/0 ebif_halt_0 bif erlang:halt/1 bif 'erl.lang.system':halt/1 ebif_halt_1 +bif erlang:halt/2 +bif 'erl.lang.system':halt/2 ebif_halt_2 bif erlang:phash/2 bif erlang:phash2/1 bif erlang:phash2/2 diff --git a/lib/hipe/cerl/erl_bif_types.erl b/lib/hipe/cerl/erl_bif_types.erl index 845df0ca61..a7ce17eb53 100644 --- a/lib/hipe/cerl/erl_bif_types.erl +++ b/lib/hipe/cerl/erl_bif_types.erl @@ -2,7 +2,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2011. All Rights Reserved. +%% Copyright Ericsson AB 2003-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -241,6 +241,7 @@ type(erl_ddll, try_unload, 2, Xs) -> %%-- erlang ------------------------------------------------------------------- type(erlang, halt, 0, _) -> t_none(); type(erlang, halt, 1, _) -> t_none(); +type(erlang, halt, 2, _) -> t_none(); type(erlang, exit, 1, _) -> t_none(); %% Note that exit/2 sends an exit signal to another process. type(erlang, exit, 2, _) -> t_atom('true'); @@ -3553,7 +3554,10 @@ arg_types(erlang, group_leader, 2) -> arg_types(erlang, halt, 0) -> []; arg_types(erlang, halt, 1) -> - [t_sup(t_non_neg_fixnum(), t_string())]; + [t_sup([t_non_neg_fixnum(), t_atom('abort'), t_string()])]; +arg_types(erlang, halt, 2) -> + [t_sup([t_non_neg_fixnum(), t_atom('abort'), t_string()]), + t_list(t_tuple([t_atom('flush'), t_boolean()]))]; arg_types(erlang, hash, 2) -> [t_any(), t_integer()]; arg_types(erlang, hd, 1) -> diff --git a/lib/stdlib/src/erl_internal.erl b/lib/stdlib/src/erl_internal.erl index cd3b531d10..3063881890 100644 --- a/lib/stdlib/src/erl_internal.erl +++ b/lib/stdlib/src/erl_internal.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1998-2011. All Rights Reserved. +%% Copyright Ericsson AB 1998-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -287,6 +287,7 @@ bif(group_leader, 0) -> true; bif(group_leader, 2) -> true; bif(halt, 0) -> true; bif(halt, 1) -> true; +bif(halt, 2) -> true; bif(hd, 1) -> true; bif(integer_to_list, 1) -> true; bif(integer_to_list, 2) -> true; -- cgit v1.2.3 From 031773afa784bcee7419e625afa39e94f947bfa8 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Mon, 19 Mar 2012 15:42:41 +0100 Subject: erts: Document erlang:halt/2 and update erlang:halt/0,1 --- erts/doc/src/erlang.xml | 66 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 13 deletions(-) diff --git a/erts/doc/src/erlang.xml b/erts/doc/src/erlang.xml index fbe7b36163..3f7ac6ac19 100644 --- a/erts/doc/src/erlang.xml +++ b/erts/doc/src/erlang.xml @@ -1432,29 +1432,69 @@ true halt() Halt the Erlang runtime system and indicate normal exit to the calling environment -

Halts the Erlang runtime system and indicates normal exit to - the calling environment. Has no return value.

+

The same as + halt(0, []).

 > halt().
-os_prompt%
+os_prompt%
halt(Status) Halt the Erlang runtime system - Status = integer() >= 0 | string() + Status = integer() >= 0 | string() | abort -

Status must be a non-negative integer, or a string. - Halts the Erlang runtime system. Has no return value. - If Status is an integer, it is returned as an exit - status of Erlang to the calling environment. - If Status is a string, produces an Erlang crash dump - with String as slogan, and then exits with a non-zero - status code.

-

Note that on many platforms, only the status codes 0-255 are - supported by the operating system.

+

The same as + halt(Status, []).

+
+> halt(17).
+os_prompt% echo $?
+17
+os_prompt% 
+
+
+ + halt(Status, Options) + Halt the Erlang runtime system + + Status = integer() >= 0 | string() | abort + Options = [Option] + Option = {flush,boolean()} | term() + + +

Status must be a non-negative integer, a string, + or the atom abort. + Halts the Erlang runtime system. Has no return value. + Depending on Status: +

+ + integer() + The runtime system exits with the integer value Status + as status code to the calling environment (operating system). + + string() + An erlang crash dump is produced with Status as slogan, + and then the runtime system exits with status code 1. + + abort + + The runtime system aborts producing a core dump, if that is + enabled in the operating system. + + +

Note that on many platforms, only the status codes 0-255 are + supported by the operating system. +

+

For integer Status the Erlang runtime system closes all ports + and allows async threads to finish their operations before exiting. + To exit without such flushing use + Option as {flush,false}. +

+

For statuses string() and abort the flush + option is ignored and flushing is not done. +

-- cgit v1.2.3 From 4cb0e5bc5227eaf675bb633f77e838b7297be87d Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Mon, 19 Mar 2012 17:02:05 +0100 Subject: erts: Basic test of erlang:halt/0..2 --- erts/emulator/test/bif_SUITE.erl | 54 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/erts/emulator/test/bif_SUITE.erl b/erts/emulator/test/bif_SUITE.erl index c7617d3b90..a21b055596 100644 --- a/erts/emulator/test/bif_SUITE.erl +++ b/erts/emulator/test/bif_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2005-2011. All Rights Reserved. +%% Copyright Ericsson AB 2005-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -28,7 +28,7 @@ types/1, t_list_to_existing_atom/1,os_env/1,otp_7526/1, binary_to_atom/1,binary_to_existing_atom/1, - atom_to_binary/1,min_max/1]). + atom_to_binary/1,min_max/1, erlang_halt/1]). suite() -> [{ct_hooks,[ts_install_cth]}]. @@ -36,7 +36,7 @@ all() -> [types, t_list_to_existing_atom, os_env, otp_7526, display, atom_to_binary, binary_to_atom, binary_to_existing_atom, - min_max]. + min_max, erlang_halt]. groups() -> []. @@ -438,7 +438,55 @@ min_max(Config) when is_list(Config) -> ok. + + +erlang_halt(Config) when is_list(Config) -> + try erlang:halt(undefined) of + _-> ?t:fail({erlang,halt,{undefined}}) + catch error:badarg -> ok end, + try halt(undefined) of + _-> ?t:fail({halt,{undefined}}) + catch error:badarg -> ok end, + try erlang:halt(undefined, []) of + _-> ?t:fail({erlang,halt,{undefined,[]}}) + catch error:badarg -> ok end, + try halt(undefined, []) of + _-> ?t:fail({halt,{undefined,[]}}) + catch error:badarg -> ok end, + try halt(0, undefined) of + _-> ?t:fail({halt,{0,undefined}}) + catch error:badarg -> ok end, + try halt(0, [undefined]) of + _-> ?t:fail({halt,{0,[undefined]}}) + catch error:badarg -> ok end, + try halt(0, [{undefined,true}]) of + _-> ?t:fail({halt,{0,[{undefined,true}]}}) + catch error:badarg -> ok end, + try halt(0, [{flush,undefined}]) of + _-> ?t:fail({halt,{0,[{flush,undefined}]}}) + catch error:badarg -> ok end, + try halt(0, [{flush,true,undefined}]) of + _-> ?t:fail({halt,{0,[{flush,true,undefined}]}}) + catch error:badarg -> ok end, + H = hostname(), + {ok,N1} = slave:start(H, halt_node1), + {badrpc,nodedown} = rpc:call(N1, erlang, halt, []), + {ok,N2} = slave:start(H, halt_node2), + {badrpc,nodedown} = rpc:call(N2, erlang, halt, [0]), + {ok,N3} = slave:start(H, halt_node3), + {badrpc,nodedown} = rpc:call(N3, erlang, halt, [0,[]]), + ok. + + + %% Helpers id(I) -> I. +hostname() -> + hostname(atom_to_list(node())). + +hostname([$@ | Hostname]) -> + list_to_atom(Hostname); +hostname([_C | Cs]) -> + hostname(Cs). -- cgit v1.2.3