[erlang-patches] init:stop/1

Magnus Froberg <>
Thu Apr 24 10:18:36 CEST 2008


Hi,

a patch that makes it possible to terminate an erlang system using
init:stop with a specified Status code (ala erlang:halt/1).

Handy if one need to terminate the system cleanly but want an
exit code that can be checked.

The patch is for R11B-2.

lake:R11B-2> svn diff lib/kernel/src/init.erl
Index: lib/kernel/src/init.erl
===================================================================
--- lib/kernel/src/init.erl     (revision 26)
+++ lib/kernel/src/init.erl     (working copy)
@@ -44,7 +44,7 @@
 %%

 -module(init).
--export([restart/0,reboot/0,stop/0,
+-export([restart/0,reboot/0,stop/0,stop/1,
         get_status/0,boot/1,get_arguments/0,get_plain_arguments/0,
         get_argument/1,script_id/0]).

@@ -129,9 +129,10 @@
            Rep
     end.

-restart() -> init ! {stop,restart},ok.
-reboot()  -> init ! {stop,reboot},ok.
-stop()    -> init ! {stop,stop},ok.
+restart()    -> init ! {stop,restart},ok.
+reboot()     -> init ! {stop,reboot},ok.
+stop()       -> init ! {stop,stop},ok.
+stop(Status) -> init ! {stop,{stop,Status}},ok.

 boot(BootArgs) ->
     register(init, self()),
@@ -468,7 +469,10 @@
     halt();
 do_stop(stop,State) ->
     stop_heart(State),
-    halt().
+    halt();
+do_stop({stop,Status},State) ->
+    stop_heart(State),
+    halt(Status).

/Magnus




More information about the erlang-patches mailing list