当Flag为master时,init:get_argument给出崩溃转储

时间:2013-09-27 08:59:39

标签: erlang

我试图使用init:get_argument(master)获取名为'master'的标志的值,这给了我一个崩溃转储。但是,如果我将'master'改为'monkey',那么工作正常。主人是保留国旗吗?

我在Windows 7 32位上运行版本5.10 / OTP R16。 这是我使用的代码:

-module(testerl_app).

-behaviour(application).

%% Application callbacks
-export([start/2, stop/1]).

%% ===================================================================
%% Application callbacks
%% ===================================================================

start(_StartType, _StartArgs) ->
    case init:get_argument(master) of
        {ok, CLIFlag} ->
            io:format("*** info command flag master has value ~p~n", [CLIFlag]);
        _ ->
            io:format("*** info no command flag master~n")
    end,
    testerl_sup:start_link().

stop(_State) ->
    ok.

这是我得到的错误:

C:\Users\xxxx\workspace\testerl>erl -pa ebin -master me -eval "application:start(testerl)"

{error_logger,{{2013,9,27},{10,48,37}},supervisor_report,[{supervisor,{local,ker
nel_sup}},{errorContext,start_error},{reason,{no_master,{badrpc,nodedown}}},{off
ender,[{pid,undefined},{name,file_server_2},{mfargs,{file_server,start_link,[]}}
,{restart_type,permanent},{shutdown,2000},{child_type,worker}]}]}
{error_logger,{{2013,9,27},{10,48,37}},crash_report,[[{initial_call,{application
_master,init,['Argument__1','Argument__2','Argument__3','Argument__4']}},{pid,<0
.9.0>},{registered_name,[]},{error_info,{exit,{{shutdown,{failed_to_start_child,
file_server_2,{no_master,{badrpc,nodedown}}}},{kernel,start,[normal,[]]}},[{appl
ication_master,init,4,[{file,"application_master.erl"},{line,133}]},{proc_lib,in
it_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]}},{ancestors,[<0.8.0>]},{me
ssages,[{'EXIT',<0.10.0>,normal}]},{links,[<0.8.0>,<0.7.0>]},{dictionary,[]},{tr
ap_exit,true},{status,running},{heap_size,376},{stack_size,27},{reductions,117}]
,[]]}
{error_logger,{{2013,9,27},{10,48,38}},std_info,[{application,kernel},{exited,{{
shutdown,{failed_to_start_child,file_server_2,{no_master,{badrpc,nodedown}}}},{k
ernel,start,[normal,[]]}}},{type,permanent}]}
{"Kernel pid terminated",application_controller,"{application_start_failure,kern
el,{{shutdown,{failed_to_start_child,file_server_2,{no_master,{badrpc,nodedown}}
}},{kernel,start,[normal,[]]}}}"}

Crash dump was written to: erl_crash.dump
Kernel pid terminated (application_controller) ({application_start_failure,kerne
l,{{shutdown,{failed_to_start_child,file_server_2,{no_master,{badrpc,nodedown}}}
},{kernel,start,[normal,[]]}}})

1 个答案:

答案 0 :(得分:3)

Erlang内核实际上将{p> -master标志用于file I/O on slave nodes

应尽可能避免将标志传递给erl,尽可能并记录在案。您应该使用普通参数或应用程序环境值。在后一种情况下,您的命令行将是:

$ erl -pa ebin -testerl master value

然后您将使用application:get_env/1,2,3检索该值。环境值也可以嵌入到版本使用的系统配置文件中(如果遵循OTP设计原则)。