aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'lib/kernel')
-rw-r--r--lib/kernel/doc/src/application.xml8
-rw-r--r--lib/kernel/doc/src/erl_ddll.xml12
-rw-r--r--lib/kernel/doc/src/file.xml19
-rw-r--r--lib/kernel/doc/src/inet.xml8
-rw-r--r--lib/kernel/doc/src/notes.xml16
-rw-r--r--lib/kernel/include/file.hrl41
-rw-r--r--lib/kernel/src/application_controller.erl234
-rw-r--r--lib/kernel/src/application_starter.erl22
-rw-r--r--lib/kernel/src/auth.erl72
-rw-r--r--lib/kernel/src/code.erl6
-rw-r--r--lib/kernel/src/code_server.erl165
-rw-r--r--lib/kernel/src/disk_log.hrl20
-rw-r--r--lib/kernel/src/disk_log_1.erl16
-rw-r--r--lib/kernel/src/erl_boot_server.erl44
-rw-r--r--lib/kernel/src/erl_epmd.erl30
-rw-r--r--lib/kernel/src/error_handler.erl18
-rw-r--r--lib/kernel/src/file.erl9
-rw-r--r--lib/kernel/src/file_io_server.erl45
-rw-r--r--lib/kernel/src/file_server.erl33
-rw-r--r--lib/kernel/src/global.erl131
-rw-r--r--lib/kernel/src/group.erl10
-rw-r--r--lib/kernel/src/heart.erl19
-rw-r--r--lib/kernel/src/inet6_tcp_dist.erl35
-rw-r--r--lib/kernel/src/inet_db.erl67
-rw-r--r--lib/kernel/src/inet_gethost_native.erl25
-rw-r--r--lib/kernel/src/kernel_config.erl27
-rw-r--r--lib/kernel/src/os.erl59
-rw-r--r--lib/kernel/src/rpc.erl61
-rw-r--r--lib/kernel/src/standard_error.erl40
-rw-r--r--lib/kernel/src/user.erl21
-rw-r--r--lib/kernel/src/wrap_log_reader.erl12
-rw-r--r--lib/kernel/test/code_SUITE.erl40
-rw-r--r--lib/kernel/test/file_SUITE.erl5
-rw-r--r--lib/kernel/test/global_SUITE.erl41
-rw-r--r--lib/kernel/test/inet_sockopt_SUITE_data/sockopt_helper.c2
-rw-r--r--lib/kernel/test/os_SUITE.erl46
-rw-r--r--lib/kernel/test/prim_file_SUITE.erl15
37 files changed, 780 insertions, 694 deletions
diff --git a/lib/kernel/doc/src/application.xml b/lib/kernel/doc/src/application.xml
index 08ef0b1e52..47d578a339 100644
--- a/lib/kernel/doc/src/application.xml
+++ b/lib/kernel/doc/src/application.xml
@@ -4,7 +4,7 @@
<erlref>
<header>
<copyright>
- <year>1996</year><year>2009</year>
+ <year>1996</year><year>2010</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
@@ -13,12 +13,12 @@
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.
-
+
</legalnotice>
<title>application</title>
@@ -503,7 +503,7 @@ Nodes = [cp1@cave, {cp2@cave, cp3@cave}]</code>
the tree.</p>
<p><c>StartType</c> defines the type of start:</p>
<list type="bulleted">
- <item><c>normal</c> if its a normal startup.</item>
+ <item><c>normal</c> if it's a normal startup.</item>
<item><c>normal</c> also if the application is distributed and
started at the current node due to a failover from another
node, and the application specification key <c>start_phases == undefined</c>.</item>
diff --git a/lib/kernel/doc/src/erl_ddll.xml b/lib/kernel/doc/src/erl_ddll.xml
index 75dca8a85d..4e65bf46f8 100644
--- a/lib/kernel/doc/src/erl_ddll.xml
+++ b/lib/kernel/doc/src/erl_ddll.xml
@@ -4,7 +4,7 @@
<erlref>
<header>
<copyright>
- <year>1997</year><year>2009</year>
+ <year>1997</year><year>2010</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
@@ -13,12 +13,12 @@
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.
-
+
</legalnotice>
<title>erl_ddll</title>
@@ -730,7 +730,7 @@
extension suffix, i.e. <c>.so</c>). The name by which
the driver identifies itself must also be consistent
with this <c>Name</c> parameter, much as a beam-file's
- module name much correspond to it's filename.</p>
+ module name much correspond to its filename.</p>
</item>
<tag><em>OptionList</em></tag>
<item>
@@ -742,8 +742,8 @@
<tag><em>{driver_options, DriverOptionsList}</em></tag>
<item>
<p>This option is to provide options that will change
- it's general behavior and will "stick" to the driver
- throughout it's lifespan.</p>
+ its general behavior and will "stick" to the driver
+ throughout its lifespan.</p>
<p>The driver options for a given driver name need
always to be consistent, <em>even when the driver is reloaded</em>, meaning that they are as much a part
of the driver as the actual name.</p>
diff --git a/lib/kernel/doc/src/file.xml b/lib/kernel/doc/src/file.xml
index f9f5443f68..50f9722a1c 100644
--- a/lib/kernel/doc/src/file.xml
+++ b/lib/kernel/doc/src/file.xml
@@ -4,7 +4,7 @@
<erlref>
<header>
<copyright>
- <year>1996</year><year>2009</year>
+ <year>1996</year><year>2010</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
@@ -13,12 +13,12 @@
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.
-
+
</legalnotice>
<title>file</title>
@@ -75,6 +75,19 @@ time() = {{Year, Month, Day}, {Hour, Minute, Second}}
</desc>
</func>
<func>
+ <name>change_mode(Filename, Mode) -> ok | {error, Reason}</name>
+ <fsummary>Change permissions of a file</fsummary>
+ <type>
+ <v>Filename = name()</v>
+ <v>Mode = int()</v>
+ <v>Reason = ext_posix()</v>
+ </type>
+ <desc>
+ <p>Changes permissions of a file. See
+ <seealso marker="#write_file_info/2">write_file_info/2</seealso>.</p>
+ </desc>
+ </func>
+ <func>
<name>change_owner(Filename, Uid) -> ok | {error, Reason}</name>
<fsummary>Change owner of a file</fsummary>
<type>
diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml
index f502b30c8d..2ae230152c 100644
--- a/lib/kernel/doc/src/inet.xml
+++ b/lib/kernel/doc/src/inet.xml
@@ -4,7 +4,7 @@
<erlref>
<header>
<copyright>
- <year>1997</year><year>2009</year>
+ <year>1997</year><year>2010</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
@@ -13,12 +13,12 @@
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.
-
+
</legalnotice>
<title>inet</title>
@@ -221,7 +221,7 @@ fe80::204:acff:fe17:bf38
</desc>
</func>
<func>
- <name>getopts(Socket, Options) -> OptionValues | {error, posix()}</name>
+ <name>getopts(Socket, Options) -> {ok, OptionValues} | {error, posix()}</name>
<fsummary>Get one or more options for a socket</fsummary>
<type>
<v>Socket = term()</v>
diff --git a/lib/kernel/doc/src/notes.xml b/lib/kernel/doc/src/notes.xml
index 7bb6aea40e..9c3f6524ae 100644
--- a/lib/kernel/doc/src/notes.xml
+++ b/lib/kernel/doc/src/notes.xml
@@ -30,6 +30,22 @@
</header>
<p>This document describes the changes made to the Kernel application.</p>
+<section><title>Kernel 2.13.5.1</title>
+
+ <section><title>Fixed Bugs and Malfunctions</title>
+ <list>
+ <item>
+ <p>
+ A race condition in <c>os:cmd/1</c> could cause the
+ caller to get stuck in <c>os:cmd/1</c> forever.</p>
+ <p>
+ Own Id: OTP-8502</p>
+ </item>
+ </list>
+ </section>
+
+</section>
+
<section><title>Kernel 2.13.5</title>
<section><title>Fixed Bugs and Malfunctions</title>
diff --git a/lib/kernel/include/file.hrl b/lib/kernel/include/file.hrl
index c1de4d764d..3889bce393 100644
--- a/lib/kernel/include/file.hrl
+++ b/lib/kernel/include/file.hrl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1997-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1997-2010. 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%
%%
@@ -21,29 +21,18 @@
-define(FILE_HRL_, 1).
%%--------------------------------------------------------------------------
-%%-type namelist() :: [char() | atom() | namelist()].
--type namelist() :: [_]. %% XXX: GROSS OVERAPPROXIMATION -- FIX ME
--type name() :: string() | atom() | namelist().
--type posix() :: atom().
-
--type date() :: {pos_integer(), pos_integer(), pos_integer()}.
--type time() :: {non_neg_integer(), non_neg_integer(), non_neg_integer()}.
--type date_time() :: {date(), time()}.
-
-%%--------------------------------------------------------------------------
-
-record(file_info,
{size :: non_neg_integer(), % Size of file in bytes.
type :: 'device' | 'directory' | 'other' | 'regular' | 'symlink',
access :: 'read' | 'write' | 'read_write' | 'none',
- atime :: date_time(), % The local time the file was last read:
- % {{Year, Mon, Day}, {Hour, Min, Sec}}.
- mtime :: date_time(), % The local time the file was last written.
- ctime :: date_time(), % The interpretation of this time field
- % is dependent on operating system.
- % On Unix it is the last time the file or
- % or the inode was changed. On Windows,
- % it is the creation time.
+ atime :: file:date_time(), % The local time the file was last read:
+ % {{Year, Mon, Day}, {Hour, Min, Sec}}.
+ mtime :: file:date_time(), % The local time the file was last written.
+ ctime :: file:date_time(), % The interpretation of this time field
+ % is dependent on operating system.
+ % On Unix it is the last time the file
+ % or the inode was changed. On Windows,
+ % it is the creation time.
mode :: integer(), % File permissions. On Windows,
% the owner permissions will be
% duplicated for group and user.
@@ -61,10 +50,8 @@
-record(file_descriptor,
- {module :: module(), % Module that handles this kind of file
+ {module :: module(), % Module that handles this kind of file
data :: term()}). % Module dependent data
--type fd() :: pid() | #file_descriptor{}.
-
%%--------------------------------------------------------------------------
-endif.
diff --git a/lib/kernel/src/application_controller.erl b/lib/kernel/src/application_controller.erl
index 7c1f059875..42f527f400 100644
--- a/lib/kernel/src/application_controller.erl
+++ b/lib/kernel/src/application_controller.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1996-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1996-2010. 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%
%%
-module(application_controller).
@@ -40,7 +40,7 @@
-export([test_change_apps/2]).
-import(lists, [zf/2, map/2, foreach/2, foldl/3,
- keysearch/3, keydelete/3, keyreplace/4]).
+ keyfind/3, keydelete/3, keyreplace/4]).
-include("application_master.hrl").
@@ -128,8 +128,13 @@
%% AppName = atom()
%% Application = App | AppName
%%-----------------------------------------------------------------
+
+-type appname() :: atom().
+
-record(state, {loading = [], starting = [], start_p_false = [], running = [],
control = [], started = [], start_req = [], conf_data}).
+-type state() :: #state{}.
+
%%-----------------------------------------------------------------
%% loading = [{AppName, From}] - Load not yet finished
%% starting = [{AppName, RestartType, Type, From}] - Start not
@@ -519,7 +524,9 @@ init(Init, Kernel) ->
end.
-%% Check the syntax of the .config file [{ApplicationName, [{Parameter, Value}]}].
+%% Check the syntax of the .config file
+%% [{ApplicationName, [{Parameter, Value}]}].
+
check_conf_data([]) ->
ok;
check_conf_data(ConfData) when is_list(ConfData) ->
@@ -563,8 +570,8 @@ check_para_kernel([]) ->
ok;
check_para_kernel([{distributed, Apps} | ParaList]) when is_list(Apps) ->
case check_distributed(Apps) of
- {error, ErrorMsg} ->
- {error, ErrorMsg};
+ {error, _ErrorMsg} = Error ->
+ Error;
_ ->
check_para_kernel(ParaList)
end;
@@ -604,6 +611,19 @@ check_para([Else | _ParaList], AppName) ->
lists:flatten(io_lib:format("~p",[Else]))}.
+-type calls() :: 'info' | 'prep_config_change' | 'which_applications'
+ | {'config_change' | 'control_application' |
+ 'load_application' | 'start_type' | 'stop_application' |
+ 'unload_application', term()}
+ | {'change_application_data', _, _}
+ | {'permit_application', atom() | {'application',atom(),_},_}
+ | {'start_application', _, _}
+ | {'unset_env', _, _}
+ | {'set_env', _, _, _}.
+
+-spec handle_call(calls(), {pid(), term()}, state()) ->
+ {'noreply', state()} | {'reply', term(), state()}.
+
handle_call({load_application, Application}, From, S) ->
case catch do_load_application(Application, S) of
{ok, NewS} ->
@@ -615,9 +635,9 @@ handle_call({load_application, Application}, From, S) ->
false ->
{reply, ok, NewS}
end;
- {error, Error} ->
- {reply, {error, Error}, S};
- {'EXIT',R} ->
+ {error, _} = Error ->
+ {reply, Error, S};
+ {'EXIT', R} ->
{reply, {error, R}, S}
end;
@@ -642,7 +662,7 @@ handle_call({start_application, AppName, RestartType}, From, S) ->
%% Incase of erroneous variables do not start the application,
%% if the application is permanent crash the node.
%% Check if the application is already starting.
- case lists:keysearch(AppName, 1, Start_req) of
+ case lists:keyfind(AppName, 1, Start_req) of
false ->
case catch check_start_cond(AppName, RestartType, Started, Running) of
{ok, Appl} ->
@@ -671,13 +691,12 @@ handle_call({start_application, AppName, RestartType}, From, S) ->
{reply, ok, SS}
end
end;
- {error, R} ->
- {reply, {error, R}, S}
+ {error, _R} = Error ->
+ {reply, Error, S}
end;
- {value, {AppName, _FromX}} ->
+ {AppName, _FromX} ->
SS = S#state{start_req = [{AppName, From} | Start_req]},
{noreply, SS}
-
end;
handle_call({permit_application, AppName, Bool}, From, S) ->
@@ -751,11 +770,11 @@ handle_call({permit_application, AppName, Bool}, From, S) ->
{noreply, SS};
%%==========================
- %% unpermit the applicaition
+ %% unpermit the application
%%==========================
%% running
{false, _, _, _, _, {value, {_AppName, Id}}} ->
- {value, {_AppName2, Type}} = keysearch(AppName, 1, Started),
+ {_AppName2, Type} = lists:keyfind(AppName, 1, Started),
stop_appl(AppName, Id, Type),
NRunning = keydelete(AppName, 1, Running),
{reply, ok, S#state{running = NRunning}};
@@ -785,9 +804,9 @@ handle_call({permit_application, AppName, Bool}, From, S) ->
handle_call({stop_application, AppName}, _From, S) ->
#state{running = Running, started = Started} = S,
- case keysearch(AppName, 1, Running) of
- {value, {_AppName, Id}} ->
- {value, {_AppName2, Type}} = keysearch(AppName, 1, Started),
+ case lists:keyfind(AppName, 1, Running) of
+ {_AppName, Id} ->
+ {_AppName2, Type} = lists:keyfind(AppName, 1, Started),
stop_appl(AppName, Id, Type),
NRunning = keydelete(AppName, 1, Running),
NStarted = keydelete(AppName, 1, Started),
@@ -813,8 +832,8 @@ handle_call({change_application_data, Applications, Config}, _From, S) ->
end,
[]),
case catch do_change_apps(Applications, Config, OldAppls) of
- {error, R} ->
- {reply, {error, R}, S};
+ {error, _} = Error ->
+ {reply, Error, S};
{'EXIT', R} ->
{reply, {error, R}, S};
NewAppls ->
@@ -868,10 +887,10 @@ handle_call({control_application, AppName}, {Pid, _Tag}, S) ->
handle_call({start_type, AppName}, _From, S) ->
Starting = S#state.starting,
- StartType = case keysearch(AppName, 1, Starting) of
+ StartType = case lists:keyfind(AppName, 1, Starting) of
false ->
local;
- {value, {_AppName, _RestartType, Type, _F}} ->
+ {_AppName, _RestartType, Type, _F} ->
Type
end,
{reply, StartType, S};
@@ -885,6 +904,9 @@ handle_call(info, _From, S) ->
{starting, S#state.starting}],
{reply, Reply, S}.
+-spec handle_cast({'application_started', appname(), _}, state()) ->
+ {'noreply', state()} | {'stop', string(), state()}.
+
handle_cast({application_started, AppName, Res}, S) ->
handle_application_started(AppName, Res, S).
@@ -892,7 +914,7 @@ handle_application_started(AppName, Res, S) ->
#state{starting = Starting, running = Running, started = Started,
start_req = Start_req} = S,
Start_reqN = reply_to_requester(AppName, Start_req, Res),
- {value, {_AppName, RestartType, _Type, _From}} = keysearch(AppName, 1, Starting),
+ {_AppName, RestartType, _Type, _From} = lists:keyfind(AppName, 1, Starting),
case Res of
{ok, Id} ->
case AppName of
@@ -907,7 +929,6 @@ handle_application_started(AppName, Res, S) ->
running = NRunning,
started = NStarted,
start_req = Start_reqN},
-
%% The permission may have been changed during start
Perm = application:get_env(kernel, permissions),
case {Perm, Id} of
@@ -918,10 +939,10 @@ handle_application_started(AppName, Res, S) ->
case lists:member({AppName, false}, Perms) of
true ->
#state{running = StopRunning, started = StopStarted} = NewS,
- case keysearch(AppName, 1, StopRunning) of
- {value, {_AppName, Id}} ->
- {value, {_AppName2, Type}} =
- keysearch(AppName, 1, StopStarted),
+ case lists:keyfind(AppName, 1, StopRunning) of
+ {_AppName, Id} ->
+ {_AppName2, Type} =
+ lists:keyfind(AppName, 1, StopStarted),
stop_appl(AppName, Id, Type),
NStopRunning = keydelete(AppName, 1, StopRunning),
cntrl(AppName, NewS, {ac_application_stopped, AppName}),
@@ -936,12 +957,8 @@ handle_application_started(AppName, Res, S) ->
_ ->
{noreply, NewS}
end;
-
-
-
-
- {error, R} when RestartType =:= temporary ->
- notify_cntrl_started(AppName, undefined, S, {error, R}),
+ {error, R} = Error when RestartType =:= temporary ->
+ notify_cntrl_started(AppName, undefined, S, Error),
info_exited(AppName, R, RestartType),
{noreply, S#state{starting = keydelete(AppName, 1, Starting),
start_req = Start_reqN}};
@@ -966,8 +983,8 @@ handle_application_started(AppName, Res, S) ->
Reason = {application_start_failure, AppName, R},
{stop, to_string(Reason), S}
end;
- {error, R} -> %% permanent
- notify_cntrl_started(AppName, undefined, S, {error, R}),
+ {error, R} = Error -> %% permanent
+ notify_cntrl_started(AppName, undefined, S, Error),
info_exited(AppName, R, RestartType),
Reason = {application_start_failure, AppName, R},
{stop, to_string(Reason), S};
@@ -977,6 +994,9 @@ handle_application_started(AppName, Res, S) ->
{stop, to_string(Reason), S}
end.
+-spec handle_info(term(), state()) ->
+ {'noreply', state()} | {'stop', string(), state()}.
+
handle_info({ac_load_application_reply, AppName, Res}, S) ->
case keysearchdelete(AppName, 1, S#state.loading) of
{value, {_AppName, From}, Loading} ->
@@ -994,12 +1014,12 @@ handle_info({ac_load_application_reply, AppName, Res}, S) ->
handle_info({ac_start_application_reply, AppName, Res}, S) ->
Start_req = S#state.start_req,
- case keysearch(AppName, 1, Starting = S#state.starting) of
- {value, {_AppName, RestartType, Type, From}} ->
+ case lists:keyfind(AppName, 1, Starting = S#state.starting) of
+ {_AppName, RestartType, Type, From} ->
case Res of
start_it ->
{true, Appl} = get_loaded(AppName),
- spawn_starter(From, Appl, S, Type),
+ spawn_starter(From, Appl, S, Type),
{noreply, S};
{started, Node} ->
handle_application_started(AppName,
@@ -1013,23 +1033,19 @@ handle_info({ac_start_application_reply, AppName, Res}, S) ->
S#state{starting = keydelete(AppName, 1, Starting),
started = [{AppName, RestartType} | Started],
start_req = Start_reqN}};
- {takeover, Node} ->
+ {takeover, _Node} = Takeover ->
{true, Appl} = get_loaded(AppName),
- spawn_starter(From, Appl, S, {takeover, Node}),
+ spawn_starter(From, Appl, S, Takeover),
NewStarting1 = keydelete(AppName, 1, Starting),
- NewStarting = [{AppName, RestartType, {takeover, Node}, From} | NewStarting1],
+ NewStarting = [{AppName, RestartType, Takeover, From} | NewStarting1],
{noreply, S#state{starting = NewStarting}};
- {error, Reason} when RestartType =:= permanent ->
- Start_reqN =
- reply_to_requester(AppName, Start_req,
- {error, Reason}),
+ {error, Reason} = Error when RestartType =:= permanent ->
+ Start_reqN = reply_to_requester(AppName, Start_req, Error),
{stop, to_string(Reason), S#state{start_req = Start_reqN}};
- {error, Reason} ->
- Start_reqN =
- reply_to_requester(AppName, Start_req,
- {error, Reason}),
+ {error, _Reason} = Error ->
+ Start_reqN = reply_to_requester(AppName, Start_req, Error),
{noreply, S#state{starting =
- keydelete(AppName, 1, Starting),
+ keydelete(AppName, 1, Starting),
start_req = Start_reqN}}
end;
false ->
@@ -1040,8 +1056,8 @@ handle_info({ac_change_application_req, AppName, Msg}, S) ->
Running = S#state.running,
Started = S#state.started,
Starting = S#state.starting,
- case {keysearch(AppName, 1, Running), keysearch(AppName, 1, Started)} of
- {{value, {AppName, Id}}, {value, {_AppName2, Type}}} ->
+ case {keyfind(AppName, 1, Running), keyfind(AppName, 1, Started)} of
+ {{AppName, Id}, {_AppName2, Type}} ->
case Msg of
{started, Node} ->
stop_appl(AppName, Id, Type),
@@ -1134,17 +1150,17 @@ handle_info({'EXIT', Pid, Reason}, S) ->
ets:match_delete(ac_tab, {{application_master, '_'}, Pid}),
NRunning = keydelete(Pid, 2, S#state.running),
NewS = S#state{running = NRunning},
- case keysearch(Pid, 2, S#state.running) of
- {value, {AppName, _AmPid}} ->
+ case lists:keyfind(Pid, 2, S#state.running) of
+ {AppName, _AmPid} ->
cntrl(AppName, S, {ac_application_stopped, AppName}),
- case keysearch(AppName, 1, S#state.started) of
- {value, {_AppName, temporary}} ->
+ case lists:keyfind(AppName, 1, S#state.started) of
+ {_AppName, temporary} ->
info_exited(AppName, Reason, temporary),
{noreply, NewS};
- {value, {_AppName, transient}} when Reason =:= normal ->
+ {_AppName, transient} when Reason =:= normal ->
info_exited(AppName, Reason, transient),
{noreply, NewS};
- {value, {_AppName, Type}} ->
+ {_AppName, Type} ->
info_exited(AppName, Reason, Type),
{stop, to_string({application_terminated, AppName, Reason}), NewS}
end;
@@ -1155,6 +1171,8 @@ handle_info({'EXIT', Pid, Reason}, S) ->
handle_info(_, S) ->
{noreply, S}.
+-spec terminate(term(), state()) -> 'ok'.
+
terminate(Reason, S) ->
case application:get_env(kernel, shutdown_func) of
{ok, {M, F}} ->
@@ -1170,8 +1188,10 @@ terminate(Reason, S) ->
(_) -> ok
end,
S#state.running),
- ets:delete(ac_tab).
+ true = ets:delete(ac_tab),
+ ok.
+-spec code_change(term(), state(), term()) -> {'ok', state()}.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
@@ -1181,8 +1201,8 @@ code_change(_OldVsn, State, _Extra) ->
%%% Internal functions
%%%-----------------------------------------------------------------
cntrl(AppName, #state{control = Control}, Msg) ->
- case keysearch(AppName, 1, Control) of
- {value, {_AppName, Pid}} ->
+ case lists:keyfind(AppName, 1, Control) of
+ {_AppName, Pid} ->
Pid ! Msg,
true;
false ->
@@ -1282,8 +1302,8 @@ check_start_cond(AppName, RestartType, Started, Running) ->
end.
do_start(AppName, RT, Type, From, S) ->
- RestartType = case keysearch(AppName, 1, S#state.started) of
- {value, {_AppName2, OldRT}} ->
+ RestartType = case lists:keyfind(AppName, 1, S#state.started) of
+ {_AppName2, OldRT} ->
get_restart_type(RT, OldRT);
false ->
RT
@@ -1295,12 +1315,12 @@ do_start(AppName, RT, Type, From, S) ->
{true, Appl} = get_loaded(AppName),
Start_req = S#state.start_req,
spawn_starter(undefined, Appl, S, Type),
- Starting = case keysearch(AppName, 1, S#state.starting) of
+ Starting = case lists:keymember(AppName, 1, S#state.starting) of
false ->
%% UW: don't know if this is necessary
[{AppName, RestartType, Type, From} |
S#state.starting];
- _ ->
+ true ->
S#state.starting
end,
S#state{starting = Starting,
@@ -1340,10 +1360,10 @@ start_appl(Appl, S, Type) ->
end
end, Appl#appl.apps),
case application_master:start_link(ApplData, Type) of
- {ok, Pid} ->
- {ok, Pid};
- {error, Reason} ->
- throw({error, Reason})
+ {ok, _Pid} = Ok ->
+ Ok;
+ {error, _Reason} = Error ->
+ throw(Error)
end
end.
@@ -1435,15 +1455,15 @@ prim_parse(Tokens, Acc) ->
case erl_parse:parse_term(Tokens2 ++ [Dot]) of
{ok, Term} ->
prim_parse(Rest, [Term | Acc]);
- {error, Reason} ->
- {error, Reason}
+ {error, _R} = Error ->
+ Error
end;
{Tokens2, []} ->
case erl_parse:parse_term(Tokens2) of
{ok, Term} ->
{ok, lists:reverse([Term | Acc])};
- {error, Reason} ->
- {error, Reason}
+ {error, _R} = Error ->
+ Error
end
end.
@@ -1456,7 +1476,7 @@ make_appl_i({application, Name, Opts}) when is_atom(Name), is_list(Opts) ->
Apps = get_opt(applications, Opts, []),
Mod =
case get_opt(mod, Opts, []) of
- {M,A} when is_atom(M) -> {M,A};
+ {M,_A}=MA when is_atom(M) -> MA;
[] -> [];
Other -> throw({error, {badstartspec, Other}})
end,
@@ -1465,8 +1485,8 @@ make_appl_i({application, Name, Opts}) when is_atom(Name), is_list(Opts) ->
MaxP = get_opt(maxP, Opts, infinity),
MaxT = get_opt(maxT, Opts, infinity),
IncApps = get_opt(included_applications, Opts, []),
- {#appl_data{name = Name, regs = Regs, mod = Mod, phases = Phases, mods = Mods,
- inc_apps = IncApps, maxP = MaxP, maxT = MaxT},
+ {#appl_data{name = Name, regs = Regs, mod = Mod, phases = Phases,
+ mods = Mods, inc_apps = IncApps, maxP = MaxP, maxT = MaxT},
Env, IncApps, Descr, Id, Vsn, Apps};
make_appl_i({application, Name, Opts}) when is_list(Opts) ->
throw({error,{invalid_name,Name}});
@@ -1545,12 +1565,12 @@ do_change_appl({ok, {ApplData, Env, IncApps, Descr, Id, Vsn, Apps}},
vsn=Vsn,
inc_apps=IncApps,
apps=Apps};
-do_change_appl({error, R}, _Appl, _ConfData) ->
- throw({error, R}).
+do_change_appl({error, _R} = Error, _Appl, _ConfData) ->
+ throw(Error).
get_opt(Key, List, Default) ->
- case keysearch(Key, 1, List) of
- {value, {_Key, Val}} -> Val;
+ case lists:keyfind(Key, 1, List) of
+ {_Key, Val} -> Val;
_ -> Default
end.
@@ -1584,8 +1604,8 @@ make_term(Str) ->
end.
get_env_i(Name, #state{conf_data = ConfData}) when is_list(ConfData) ->
- case keysearch(Name, 1, ConfData) of
- {value, {_Name, Env}} -> Env;
+ case lists:keyfind(Name, 1, ConfData) of
+ {_Name, Env} -> Env;
_ -> []
end;
get_env_i(_Name, _) -> [].
@@ -1605,9 +1625,6 @@ merge_env([{App, AppEnv1} | T], Env2, Res) ->
merge_env([], Env2, Res) ->
Env2 ++ Res.
-
-
-
%% Merges envs for an application. Env2 overrides Env1
merge_app_env(Env1, Env2) ->
merge_app_env(Env1, Env2, []).
@@ -1671,13 +1688,12 @@ do_config_change([], _EnvBefore, Errors) ->
{error, Errors};
do_config_change([{App, _Id} | Apps], EnvBefore, Errors) ->
AppEnvNow = lists:sort(application:get_all_env(App)),
- AppEnvBefore = case lists:keysearch(App, 1, EnvBefore) of
+ AppEnvBefore = case lists:keyfind(App, 1, EnvBefore) of
false ->
[];
- {value, {App, AppEnvBeforeT}} ->
+ {App, AppEnvBeforeT} ->
lists:sort(AppEnvBeforeT)
end,
-
Res =
case AppEnvNow of
AppEnvBefore ->
@@ -1697,12 +1713,12 @@ do_config_change([{App, _Id} | Apps], EnvBefore, Errors) ->
%% if the cb-function is not defined
{'EXIT', {undef, _}} ->
ok;
- {error, Error} ->
- {error, Error};
+ {error, _} = Error ->
+ Error;
Else ->
{error, Else}
end;
- {ok,[]} ->
+ {ok, []} ->
{error, {module_not_defined, App}};
undefined ->
{error, {application_not_found, App}}
@@ -1716,9 +1732,7 @@ do_config_change([{App, _Id} | Apps], EnvBefore, Errors) ->
{error, NewError} ->
do_config_change(Apps, EnvBefore,[NewError | Errors])
end.
-
-
-
+
%%-----------------------------------------------------------------
%% Check if the configuration is changed in anyway.
@@ -1732,21 +1746,17 @@ do_config_diff([], AppEnvBefore, {Changed, New}) ->
do_config_diff(AppEnvNow, [], {Changed, New}) ->
{Changed, AppEnvNow++New, []};
do_config_diff([{Env, Value} | AppEnvNow], AppEnvBefore, {Changed, New}) ->
- case lists:keysearch(Env, 1, AppEnvBefore) of
- {value, {Env, Value}} ->
+ case lists:keyfind(Env, 1, AppEnvBefore) of
+ {Env, Value} ->
do_config_diff(AppEnvNow, lists:keydelete(Env,1,AppEnvBefore), {Changed, New});
- {value, {Env, _OtherValue}} ->
+ {Env, _OtherValue} ->
do_config_diff(AppEnvNow, lists:keydelete(Env,1,AppEnvBefore),
{[{Env, Value} | Changed], New});
false ->
do_config_diff(AppEnvNow, AppEnvBefore, {Changed, [{Env, Value}|New]})
end.
-
-
-
-
%%-----------------------------------------------------------------
%% Read the .config files.
%%-----------------------------------------------------------------
@@ -1901,14 +1911,13 @@ reply_to_requester(AppName, Start_req, Res) ->
%% Update the environment variable permission for an application.
%%-----------------------------------------------------------------
update_permissions(AppName, Bool) ->
- case ets:lookup(ac_tab, {env, kernel, permissions}) of
+ T = {env, kernel, permissions},
+ case ets:lookup(ac_tab, T) of
[] ->
- ets:insert(ac_tab, {{env, kernel, permissions},
- [{AppName, Bool}]});
+ ets:insert(ac_tab, {T, [{AppName, Bool}]});
[{_, Perm}] ->
Perm2 = lists:keydelete(AppName, 1, Perm),
- ets:insert(ac_tab, {{env, kernel, permissions},
- [{AppName, Bool}| Perm2]})
+ ets:insert(ac_tab, {T, [{AppName, Bool}|Perm2]})
end.
%%-----------------------------------------------------------------
@@ -1937,6 +1946,9 @@ test_make_apps([A|Apps], Res) ->
%% Exit reason needs to be a printable string
%% (and of length <200, but init now does the chopping).
%%-----------------------------------------------------------------
+
+-spec to_string(term()) -> string().
+
to_string(Term) ->
case io_lib:printable_list(Term) of
true ->
diff --git a/lib/kernel/src/application_starter.erl b/lib/kernel/src/application_starter.erl
index 8d839e4662..564366f304 100644
--- a/lib/kernel/src/application_starter.erl
+++ b/lib/kernel/src/application_starter.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1998-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1998-2010. 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%
%%
%% ----------------------------------------------------------------------
@@ -42,8 +42,8 @@ start([], _Type, _Apps) ->
ok;
start([{Phase,_PhaseArgs}|Phases], Type, Apps) ->
case start_apps(Phase, Type, Apps) of
- {error, Error} ->
- {error, Error};
+ {error, _} = Error ->
+ Error;
_ ->
start(Phases, Type, Apps)
end.
@@ -56,8 +56,8 @@ start_apps(_Phase, _Type, []) ->
ok;
start_apps(Phase, Type, [App | Apps]) ->
case catch run_start_phase(Phase, Type, App) of
- {error, Error} ->
- {error, Error};
+ {error, _} = Error ->
+ Error;
_ ->
start_apps(Phase, Type, Apps)
end.
@@ -91,10 +91,10 @@ run_the_phase(Phase, Type, App, Mod) ->
{ok, Sp} ->
Sp
end,
- case lists:keysearch(Phase, 1, Start_phases) of
+ case lists:keyfind(Phase, 1, Start_phases) of
false ->
ok;
- {value, {Phase, PhaseArgs}} ->
+ {Phase, PhaseArgs} ->
case catch Mod:start_phase(Phase, Type, PhaseArgs) of
ok ->
ok;
diff --git a/lib/kernel/src/auth.erl b/lib/kernel/src/auth.erl
index 62c0bef0cc..7fe30ae828 100644
--- a/lib/kernel/src/auth.erl
+++ b/lib/kernel/src/auth.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1996-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1996-2010. 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%
%%
-module(auth).
@@ -37,10 +37,12 @@
-define(COOKIE_ETS_PROTECTION, protected).
+-type cookie() :: atom().
-record(state, {
- our_cookie, %% Our own cookie
- other_cookies %% The send-cookies of other nodes
+ our_cookie :: cookie(), %% Our own cookie
+ other_cookies :: ets:tab() %% The send-cookies of other nodes
}).
+-type state() :: #state{}.
-include("../include/file.hrl").
@@ -61,24 +63,24 @@ is_auth(Node) ->
pang -> no
end.
--spec cookie() -> atom().
+-spec cookie() -> cookie().
cookie() ->
get_cookie().
--spec cookie(Cookies :: [atom(),...] | atom()) -> 'true'.
+-spec cookie(Cookies :: [cookie(),...] | cookie()) -> 'true'.
cookie([Cookie]) ->
set_cookie(Cookie);
cookie(Cookie) ->
set_cookie(Cookie).
--spec node_cookie(Cookies :: [atom(),...]) -> 'yes' | 'no'.
+-spec node_cookie(Cookies :: [node() | cookie(),...]) -> 'yes' | 'no'.
node_cookie([Node, Cookie]) ->
node_cookie(Node, Cookie).
--spec node_cookie(Node :: node(), Cookie :: atom()) -> 'yes' | 'no'.
+-spec node_cookie(Node :: node(), Cookie :: cookie()) -> 'yes' | 'no'.
node_cookie(Node, Cookie) ->
set_cookie(Node, Cookie),
@@ -86,24 +88,24 @@ node_cookie(Node, Cookie) ->
%%--"New" interface-----------------------------------------------------
--spec get_cookie() -> atom().
+-spec get_cookie() -> 'nocookie' | cookie().
get_cookie() ->
get_cookie(node()).
--spec get_cookie(Node :: node()) -> atom().
+-spec get_cookie(Node :: node()) -> 'nocookie' | cookie().
get_cookie(_Node) when node() =:= nonode@nohost ->
nocookie;
get_cookie(Node) ->
gen_server:call(auth, {get_cookie, Node}).
--spec set_cookie(Cookie :: atom()) -> 'true'.
+-spec set_cookie(Cookie :: cookie()) -> 'true'.
set_cookie(Cookie) ->
set_cookie(node(), Cookie).
--spec set_cookie(Node :: node(), Cookie :: atom()) -> 'true'.
+-spec set_cookie(Node :: node(), Cookie :: cookie()) -> 'true'.
set_cookie(_Node, _Cookie) when node() =:= nonode@nohost ->
erlang:error(distribution_not_started);
@@ -117,11 +119,13 @@ sync_cookie() ->
-spec print(Node :: node(), Format :: string(), Args :: [_]) -> 'ok'.
-print(Node,Format,Args) ->
- (catch gen_server:cast({auth,Node},{print,Format,Args})).
+print(Node, Format, Args) ->
+ (catch gen_server:cast({auth, Node}, {print, Format, Args})).
%%--gen_server callbacks------------------------------------------------
+-spec init([]) -> {'ok', state()}.
+
init([]) ->
process_flag(trap_exit, true),
{ok, init_cookie()}.
@@ -130,6 +134,11 @@ init([]) ->
%% The net kernel will let all message to the auth server
%% through as is
+-type calls() :: 'echo' | 'sync_cookie' | {'set_cookie', node(), term()}.
+
+-spec handle_call(calls(), {pid(), term()}, state()) ->
+ {'reply', 'hello' | 'true' | 'nocookie' | cookie(), state()}.
+
handle_call({get_cookie, Node}, {_From,_Tag}, State) when Node =:= node() ->
{reply, State#state.our_cookie, State};
handle_call({get_cookie, Node}, {_From,_Tag}, State) ->
@@ -145,7 +154,7 @@ handle_call({set_cookie, Node, Cookie}, {_From,_Tag}, State)
%%
%% Happens when the distribution is brought up and
-%% Someone wight have set up the cookie for our new nodename.
+%% someone might have set up the cookie for our new node name.
%%
handle_call({set_cookie, Node, Cookie}, {_From,_Tag}, State) ->
@@ -153,9 +162,9 @@ handle_call({set_cookie, Node, Cookie}, {_From,_Tag}, State) ->
{reply, true, State};
handle_call(sync_cookie, _From, State) ->
- case ets:lookup(State#state.other_cookies,node()) of
+ case ets:lookup(State#state.other_cookies, node()) of
[{_N,C}] ->
- ets:delete(State#state.other_cookies,node()),
+ ets:delete(State#state.other_cookies, node()),
{reply, true, State#state{our_cookie = C}};
[] ->
{reply, true, State}
@@ -164,13 +173,22 @@ handle_call(sync_cookie, _From, State) ->
handle_call(echo, _From, O) ->
{reply, hello, O}.
+%%
+%% handle_cast/2
+%%
+
+-spec handle_cast({'print', string(), [term()]}, state()) ->
+ {'noreply', state()}.
+
handle_cast({print,What,Args}, O) ->
%% always allow print outs
- error_logger:error_msg(What,Args),
+ error_logger:error_msg(What, Args),
{noreply, O}.
%% A series of bad messages that may come (from older distribution versions).
+-spec handle_info(term(), state()) -> {'noreply', state()}.
+
handle_info({From,badcookie,net_kernel,{From,spawn,_M,_F,_A,_Gleader}}, O) ->
auth:print(node(From) ,"~n** Unauthorized spawn attempt to ~w **~n",
[node()]),
@@ -188,10 +206,10 @@ handle_info({_From,badcookie,ddd_server,_Mess}, O) ->
{noreply, O};
handle_info({From,badcookie,rex,_Msg}, O) ->
auth:print(getnode(From),
- "~n** Unauthorized rpc attempt to ~w **~n",[node()]),
+ "~n** Unauthorized rpc attempt to ~w **~n", [node()]),
disconnect_node(node(From)),
{noreply, O};
-%% These two messages has to do with the old auth:is_auth() call (net_adm:ping)
+%% These two messages have to do with the old auth:is_auth() call (net_adm:ping)
handle_info({From,badcookie,net_kernel,{'$gen_call',{From,Tag},{is_auth,_Node}}}, O) -> %% ho ho
From ! {Tag, no},
{noreply, O};
@@ -215,12 +233,16 @@ handle_info({From,badcookie,Name,Mess}, Opened) ->
end
end,
{noreply, Opened};
-handle_info(_, O)-> % Ignore anything else especially EXIT signals
+handle_info(_, O) -> % Ignore anything else especially EXIT signals
{noreply, O}.
+-spec code_change(term(), state(), term()) -> {'ok', state()}.
+
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
+-spec terminate(term(), state()) -> 'ok'.
+
terminate(_Reason, _State) ->
ok.
@@ -260,7 +282,7 @@ init_cookie() ->
end;
_Other ->
#state{our_cookie = nocookie,
- other_cookies = ets:new(cookies,[?COOKIE_ETS_PROTECTION])}
+ other_cookies = ets:new(cookies, [?COOKIE_ETS_PROTECTION])}
end.
read_cookie() ->
diff --git a/lib/kernel/src/code.erl b/lib/kernel/src/code.erl
index ffe58ae7a9..affa5fc0fd 100644
--- a/lib/kernel/src/code.erl
+++ b/lib/kernel/src/code.erl
@@ -425,8 +425,8 @@ where_is_file(Path, File) when is_list(Path), is_list(File) ->
FileInfo :: #file_info{})
-> 'ok' | {'error', atom()}.
-set_primary_archive(ArchiveFile0, ArchiveBin, FileInfo)
- when is_list(ArchiveFile0), is_binary(ArchiveBin), is_record(FileInfo, file_info) ->
+set_primary_archive(ArchiveFile0, ArchiveBin, #file_info{} = FileInfo)
+ when is_list(ArchiveFile0), is_binary(ArchiveBin) ->
ArchiveFile = filename:absname(ArchiveFile0),
case call({set_primary_archive, ArchiveFile, ArchiveBin, FileInfo}) of
{ok, []} ->
@@ -473,7 +473,7 @@ decorate([], _) -> [];
decorate([File|Tail], Dir) ->
[{Dir, File} | decorate(Tail, Dir)].
-filter(_Ext, Dir, {error,_}) ->
+filter(_Ext, Dir, error) ->
io:format("** Bad path can't read ~s~n", [Dir]), [];
filter(Ext, _, {ok,Files}) ->
filter2(Ext, length(Ext), Files).
diff --git a/lib/kernel/src/code_server.erl b/lib/kernel/src/code_server.erl
index 7aeddb73d1..4a1fc7df34 100644
--- a/lib/kernel/src/code_server.erl
+++ b/lib/kernel/src/code_server.erl
@@ -32,14 +32,15 @@
-import(lists, [foreach/2]).
--record(state,{supervisor,
- root,
- path,
- moddb,
- namedb,
- cache = no_cache,
- mode=interactive,
- on_load = []}).
+-record(state, {supervisor,
+ root,
+ path,
+ moddb,
+ namedb,
+ cache = no_cache,
+ mode = interactive,
+ on_load = []}).
+-type state() :: #state{}.
start_link(Args) ->
Ref = make_ref(),
@@ -65,8 +66,8 @@ init(Ref, Parent, [Root,Mode0]) ->
Mode =
case Mode0 of
- minimal -> interactive;
- _ -> Mode0
+ minimal -> interactive;
+ _ -> Mode0
end,
IPath =
@@ -74,7 +75,7 @@ init(Ref, Parent, [Root,Mode0]) ->
interactive ->
LibDir = filename:append(Root, "lib"),
{ok,Dirs} = erl_prim_loader:list_dir(LibDir),
- {Paths,_Libs} = make_path(LibDir,Dirs),
+ {Paths,_Libs} = make_path(LibDir, Dirs),
UserLibPaths = get_user_lib_dirs(),
["."] ++ UserLibPaths ++ Paths;
_ ->
@@ -97,7 +98,7 @@ init(Ref, Parent, [Root,Mode0]) ->
end,
Parent ! {Ref,{ok,self()}},
- loop(State#state{supervisor=Parent}).
+ loop(State#state{supervisor = Parent}).
get_user_lib_dirs() ->
case os:getenv("ERL_LIBS") of
@@ -169,8 +170,8 @@ loop(#state{supervisor=Supervisor}=State0) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% System upgrade
-handle_system_msg(SysState,Msg,From,Parent,Misc) ->
- case do_sys_cmd(SysState,Msg,Parent, Misc) of
+handle_system_msg(SysState, Msg, From, Parent, Misc) ->
+ case do_sys_cmd(SysState, Msg, Parent, Misc) of
{suspended, Reply, NMisc} ->
gen_reply(From, Reply),
suspend_loop(suspended, Parent, NMisc);
@@ -207,7 +208,7 @@ do_sys_cmd(SysState, {debug, _What}, _Parent, Misc) ->
do_sys_cmd(suspended, {change_code, Module, Vsn, Extra}, _Parent, Misc0) ->
{Res, Misc} =
case catch ?MODULE:system_code_change(Misc0, Module, Vsn, Extra) of
- {ok, Misc1} -> {ok, Misc1};
+ {ok, _} = Ok -> Ok;
Else -> {{error, Else}, Misc0}
end,
{suspended, Res, Misc};
@@ -218,9 +219,10 @@ system_continue(_Parent, _Debug, State) ->
loop(State).
system_terminate(_Reason, _Parent, _Debug, _State) ->
-% error_msg("~p terminating: ~p~n ",[?MODULE,Reason]),
+ %% error_msg("~p terminating: ~p~n ", [?MODULE, Reason]),
exit(shutdown).
+-spec system_code_change(state(), module(), term(), term()) -> {'ok', state()}.
system_code_change(State, _Module, _OldVsn, _Extra) ->
{ok, State}.
@@ -240,7 +242,7 @@ handle_call({stick_mod,Mod}, {_From,_Tag}, S) ->
handle_call({unstick_mod,Mod}, {_From,_Tag}, S) ->
{reply,stick_mod(Mod, false, S),S};
-handle_call({dir,Dir},{_From,_Tag}, S) ->
+handle_call({dir,Dir}, {_From,_Tag}, S) ->
Root = S#state.root,
Resp = do_dir(Root,Dir,S#state.namedb),
{reply,Resp,S};
@@ -253,43 +255,47 @@ handle_call({load_file,Mod}, Caller, St) ->
load_file(Mod, Caller, St)
end;
-handle_call({add_path,Where,Dir0}, {_From,_Tag}, S=#state{cache=Cache0}) ->
+handle_call({add_path,Where,Dir0}, {_From,_Tag},
+ #state{cache=Cache0,namedb=Namedb,path=Path0}=S) ->
case Cache0 of
no_cache ->
- {Resp,Path} = add_path(Where, Dir0, S#state.path, S#state.namedb),
+ {Resp,Path} = add_path(Where, Dir0, Path0, Namedb),
{reply,Resp,S#state{path=Path}};
_ ->
Dir = absname(Dir0), %% Cache always expands the path
- {Resp,Path} = add_path(Where, Dir, S#state.path, S#state.namedb),
- Cache=update_cache([Dir],Where,Cache0),
+ {Resp,Path} = add_path(Where, Dir, Path0, Namedb),
+ Cache = update_cache([Dir], Where, Cache0),
{reply,Resp,S#state{path=Path,cache=Cache}}
end;
-handle_call({add_paths,Where,Dirs0}, {_From,_Tag}, S=#state{cache=Cache0}) ->
+handle_call({add_paths,Where,Dirs0}, {_From,_Tag},
+ #state{cache=Cache0,namedb=Namedb,path=Path0}=S) ->
case Cache0 of
no_cache ->
- {Resp,Path} = add_paths(Where,Dirs0,S#state.path,S#state.namedb),
- {reply,Resp, S#state{path=Path}};
+ {Resp,Path} = add_paths(Where, Dirs0, Path0, Namedb),
+ {reply,Resp,S#state{path=Path}};
_ ->
%% Cache always expands the path
Dirs = [absname(Dir) || Dir <- Dirs0],
- {Resp,Path} = add_paths(Where, Dirs, S#state.path, S#state.namedb),
+ {Resp,Path} = add_paths(Where, Dirs, Path0, Namedb),
Cache=update_cache(Dirs,Where,Cache0),
{reply,Resp,S#state{cache=Cache,path=Path}}
end;
-handle_call({set_path,PathList}, {_From,_Tag}, S) ->
- Path = S#state.path,
- {Resp, NewPath,NewDb} = set_path(PathList, Path, S#state.namedb),
- {reply,Resp,rehash_cache(S#state{path = NewPath, namedb=NewDb})};
+handle_call({set_path,PathList}, {_From,_Tag},
+ #state{path=Path0,namedb=Namedb}=S) ->
+ {Resp,Path,NewDb} = set_path(PathList, Path0, Namedb),
+ {reply,Resp,rehash_cache(S#state{path=Path,namedb=NewDb})};
-handle_call({del_path,Name}, {_From,_Tag}, S) ->
- {Resp,Path} = del_path(Name,S#state.path,S#state.namedb),
- {reply,Resp,rehash_cache(S#state{path = Path})};
+handle_call({del_path,Name}, {_From,_Tag},
+ #state{path=Path0,namedb=Namedb}=S) ->
+ {Resp,Path} = del_path(Name, Path0, Namedb),
+ {reply,Resp,rehash_cache(S#state{path=Path})};
-handle_call({replace_path,Name,Dir}, {_From,_Tag}, S) ->
- {Resp,Path} = replace_path(Name,Dir,S#state.path,S#state.namedb),
- {reply,Resp,rehash_cache(S#state{path = Path})};
+handle_call({replace_path,Name,Dir}, {_From,_Tag},
+ #state{path=Path0,namedb=Namedb}=S) ->
+ {Resp,Path} = replace_path(Name, Dir, Path0, Namedb),
+ {reply,Resp,rehash_cache(S#state{path=Path})};
handle_call(rehash, {_From,_Tag}, S0) ->
S = create_cache(S0),
@@ -311,12 +317,12 @@ handle_call({load_binary,Mod,File,Bin}, Caller, S) ->
do_load_binary(Mod, File, Bin, Caller, S);
handle_call({load_native_partial,Mod,Bin}, {_From,_Tag}, S) ->
- Result = (catch hipe_unified_loader:load(Mod,Bin)),
+ Result = (catch hipe_unified_loader:load(Mod, Bin)),
Status = hipe_result_to_status(Result),
{reply,Status,S};
handle_call({load_native_sticky,Mod,Bin,WholeModule}, {_From,_Tag}, S) ->
- Result = (catch hipe_unified_loader:load_module(Mod,Bin,WholeModule)),
+ Result = (catch hipe_unified_loader:load_module(Mod, Bin, WholeModule)),
Status = hipe_result_to_status(Result),
{reply,Status,S};
@@ -388,8 +394,8 @@ handle_call({set_primary_archive, File, ArchiveBin, FileInfo}, {_From,_Tag}, S=#
case erl_prim_loader:set_primary_archive(File, ArchiveBin, FileInfo) of
{ok, Files} ->
{reply, {ok, Mode, Files}, S};
- {error, Reason} ->
- {reply, {error, Reason}, S}
+ {error, _Reason} = Error ->
+ {reply, Error, S}
end;
handle_call({is_cached,File}, {_From,_Tag}, S=#state{cache=Cache}) ->
@@ -469,8 +475,8 @@ locate_mods([], _, _, Cache, Path) ->
filter_mods([File|Rest], Where, Exts, Dir, Cache) ->
Ext = filename:extension(File),
Root = list_to_atom(filename:rootname(File, Ext)),
- case lists:keysearch(Ext, 2, Exts) of
- {value,{Type,_}} ->
+ case lists:keyfind(Ext, 2, Exts) of
+ {Type, _} ->
Key = {Type,Root},
case Where of
first ->
@@ -487,7 +493,6 @@ filter_mods([File|Rest], Where, Exts, Dir, Cache) ->
ok
end,
filter_mods(Rest, Where, Exts, Dir, Cache);
-
filter_mods([], _, _, _, Cache) ->
Cache.
@@ -498,27 +503,27 @@ filter_mods([], _, _, _, Cache) ->
%%
%% Create the initial path.
%%
-make_path(BundleDir,Bundles0) ->
+make_path(BundleDir, Bundles0) ->
Bundles = choose_bundles(Bundles0),
- make_path(BundleDir,Bundles,[],[]).
+ make_path(BundleDir, Bundles, [], []).
choose_bundles(Bundles) ->
ArchiveExt = archive_extension(),
- Bs = lists:sort([create_bundle(B,ArchiveExt) || B <- Bundles]),
+ Bs = lists:sort([create_bundle(B, ArchiveExt) || B <- Bundles]),
[FullName || {_Name,_NumVsn,FullName} <-
choose(lists:reverse(Bs), [], ArchiveExt)].
-create_bundle(FullName,ArchiveExt) ->
- BaseName = filename:basename(FullName,ArchiveExt),
+create_bundle(FullName, ArchiveExt) ->
+ BaseName = filename:basename(FullName, ArchiveExt),
case split(BaseName, "-") of
- Toks when length(Toks) > 1 ->
+ [_, _|_] = Toks ->
VsnStr = lists:last(Toks),
case vsn_to_num(VsnStr) of
{ok, VsnNum} ->
- Name = join(lists:sublist(Toks,length(Toks)-1),"-"),
+ Name = join(lists:sublist(Toks, length(Toks)-1),"-"),
{Name,VsnNum,FullName};
false ->
- {FullName, [0], FullName}
+ {FullName,[0],FullName}
end;
_ ->
{FullName,[0],FullName}
@@ -569,8 +574,8 @@ join([], _) ->
[].
choose([{Name,NumVsn,NewFullName}=New|Bs], Acc, ArchiveExt) ->
- case lists:keysearch(Name,1,Acc) of
- {value, {_, NV, OldFullName}} when NV =:= NumVsn ->
+ case lists:keyfind(Name, 1, Acc) of
+ {_, NV, OldFullName} when NV =:= NumVsn ->
case filename:extension(OldFullName) =:= ArchiveExt of
false ->
choose(Bs,Acc, ArchiveExt);
@@ -578,7 +583,7 @@ choose([{Name,NumVsn,NewFullName}=New|Bs], Acc, ArchiveExt) ->
Acc2 = lists:keystore(Name, 1, Acc, New),
choose(Bs,Acc2, ArchiveExt)
end;
- {value, {_, _, _}} ->
+ {_, _, _} ->
choose(Bs,Acc, ArchiveExt);
false ->
choose(Bs,[{Name,NumVsn,NewFullName}|Acc], ArchiveExt)
@@ -602,8 +607,8 @@ make_path(BundleDir,[Bundle|Tail],Res,Bs) ->
Ebin2 = filename:join([filename:dirname(Dir), Base ++ Ext, Base, "ebin"]),
Ebins =
case split(Base, "-") of
- Toks when length(Toks) > 1 ->
- AppName = join(lists:sublist(Toks,length(Toks)-1),"-"),
+ [_, _|_] = Toks ->
+ AppName = join(lists:sublist(Toks, length(Toks)-1),"-"),
Ebin3 = filename:join([filename:dirname(Dir), Base ++ Ext, AppName, "ebin"]),
[Ebin3, Ebin2, Dir];
_ ->
@@ -835,30 +840,25 @@ add_path(_,_,Path,_) ->
%% then the table is created :-)
%%
do_add(first,Dir,Path,NameDb) ->
- update(Dir,NameDb),
+ update(Dir, NameDb),
[Dir|lists:delete(Dir,Path)];
do_add(last,Dir,Path,NameDb) ->
case lists:member(Dir,Path) of
true ->
Path;
false ->
- maybe_update(Dir,NameDb),
+ maybe_update(Dir, NameDb),
Path ++ [Dir]
end.
%% Do not update if the same name already exists !
-maybe_update(Dir,NameDb) ->
- case lookup_name(get_name(Dir),NameDb) of
- false -> update(Dir,NameDb);
- _ -> false
- end.
+maybe_update(Dir, NameDb) ->
+ (lookup_name(get_name(Dir), NameDb) =:= false) andalso update(Dir, NameDb).
update(_Dir, false) ->
- ok;
-update(Dir,NameDb) ->
- replace_name(Dir,NameDb).
-
-
+ true;
+update(Dir, NameDb) ->
+ replace_name(Dir, NameDb).
%%
%% Set a completely new path.
@@ -946,8 +946,8 @@ all_archive_subdirs(AppDir) ->
Base = filename:basename(AppDir),
Dirs =
case split(Base, "-") of
- Toks when length(Toks) > 1 ->
- Base2 = join(lists:sublist(Toks,length(Toks)-1),"-"),
+ [_, _|_] = Toks ->
+ Base2 = join(lists:sublist(Toks, length(Toks)-1), "-"),
[Base2, Base];
_ ->
[Base]
@@ -1060,7 +1060,6 @@ check_pars(Name,Dir) ->
{error,bad_name}
end.
-
del_ebin(Dir) ->
case filename:basename(Dir) of
"ebin" ->
@@ -1079,8 +1078,6 @@ del_ebin(Dir) ->
Dir
end.
-
-
replace_name(Dir, Db) ->
case get_name(Dir) of
Dir ->
@@ -1187,15 +1184,7 @@ get_mods([File|Tail], Extension) ->
get_mods([], _) -> [].
is_sticky(Mod, Db) ->
- case erlang:module_loaded(Mod) of
- true ->
- case ets:lookup(Db, {sticky,Mod}) of
- [] -> false;
- _ -> true
- end;
- false ->
- false
- end.
+ erlang:module_loaded(Mod) andalso (ets:lookup(Db, {sticky, Mod}) =/= []).
add_paths(Where,[Dir|Tail],Path,NameDb) ->
{_,NPath} = add_path(Where,Dir,Path,NameDb),
@@ -1203,7 +1192,6 @@ add_paths(Where,[Dir|Tail],Path,NameDb) ->
add_paths(_,_,Path,_) ->
{ok,Path}.
-
do_load_binary(Module, File, Binary, Caller, St) ->
case modp(Module) andalso modp(File) andalso is_binary(Binary) of
true ->
@@ -1220,7 +1208,6 @@ modp(Atom) when is_atom(Atom) -> true;
modp(List) when is_list(List) -> int_list(List);
modp(_) -> false.
-
load_abs(File, Mod0, Caller, St) ->
Ext = objfile_extension(),
FileName0 = lists:concat([File, Ext]),
@@ -1263,20 +1250,20 @@ try_load_module_1(File, Mod, Bin, Caller, #state{moddb=Db}=St) ->
{reply,{error,sticky_directory},St};
false ->
case catch load_native_code(Mod, Bin) of
- {module,Mod} ->
+ {module,Mod} = Module ->
ets:insert(Db, {Mod,File}),
- {reply,{module,Mod},St};
+ {reply,Module,St};
no_native ->
case erlang:load_module(Mod, Bin) of
- {module,Mod} ->
+ {module,Mod} = Module ->
ets:insert(Db, {Mod,File}),
post_beam_load(Mod),
- {reply,{module,Mod},St};
+ {reply,Module,St};
{error,on_load} ->
handle_on_load(Mod, File, Caller, St);
- {error,What} ->
+ {error,What} = Error ->
error_msg("Loading of ~s failed: ~p\n", [File, What]),
- {reply,{error,What},St}
+ {reply,Error,St}
end;
Error ->
error_msg("Native loading of ~s failed: ~p\n",
diff --git a/lib/kernel/src/disk_log.hrl b/lib/kernel/src/disk_log.hrl
index b0849145ca..9a94d4d3b9 100644
--- a/lib/kernel/src/disk_log.hrl
+++ b/lib/kernel/src/disk_log.hrl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1997-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1997-2010. 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%
%%
@@ -44,17 +44,11 @@
-define(OPENED, <<6,7,8,9>>).
-define(CLOSED, <<99,88,77,11>>).
-%% Needed for the definition of fd()
+%% Needed for the definition of #file_info{}
%% Must use include_lib() so that we always can be sure to find
%% file.hrl. A relative path will not work in an installed system.
-include_lib("kernel/include/file.hrl").
-%% Ugly workaround. If we are building the bootstrap compiler,
-%% file.hrl does not define the fd() type.
--ifndef(FILE_HRL_).
--type fd() :: pid() | #file_descriptor{}.
--endif.
-
%%------------------------------------------------------------------------
%% Types -- alphabetically
%%------------------------------------------------------------------------
@@ -94,7 +88,7 @@
options = [] :: dlog_options()}).
-record(cache, %% Cache for logged terms (per file descriptor).
- {fd :: fd(), %% File descriptor.
+ {fd :: file:fd(), %% File descriptor.
sz = 0 :: non_neg_integer(), %% Number of bytes in the cache.
c = [] :: iodata()} %% The cache.
).
diff --git a/lib/kernel/src/disk_log_1.erl b/lib/kernel/src/disk_log_1.erl
index 7103417149..8ccdb88d12 100644
--- a/lib/kernel/src/disk_log_1.erl
+++ b/lib/kernel/src/disk_log_1.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1997-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1997-2010. 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%
%%
-module(disk_log_1).
@@ -1529,7 +1529,7 @@ write_cache(Fd, FileName, C) ->
Error -> {catch file_error(FileName, Error), #cache{fd = Fd}}
end.
--spec write_cache_close(fd(), file:filename(), iodata()) -> #cache{}. % | throw(Error)
+-spec write_cache_close(file:fd(), file:filename(), iodata()) -> #cache{}. % | throw(Error)
write_cache_close(Fd, _FileName, []) ->
#cache{fd = Fd};
@@ -1539,12 +1539,12 @@ write_cache_close(Fd, FileName, C) ->
Error -> file_error_close(Fd, FileName, Error)
end.
--spec file_error(file:filename(), {'error', atom()}) -> no_return().
+-spec file_error(file:filename(), {'error', file:posix()}) -> no_return().
file_error(FileName, {error, Error}) ->
throw({error, {file_error, FileName, Error}}).
--spec file_error_close(fd(), file:filename(), {'error', atom()}) -> no_return().
+-spec file_error_close(file:fd(), file:filename(), {'error', file:posix()}) -> no_return().
file_error_close(Fd, FileName, {error, Error}) ->
file:close(Fd),
diff --git a/lib/kernel/src/erl_boot_server.erl b/lib/kernel/src/erl_boot_server.erl
index 702b2feac9..b4c5f5e27c 100644
--- a/lib/kernel/src/erl_boot_server.erl
+++ b/lib/kernel/src/erl_boot_server.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1996-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1996-2010. 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%
%%
%% A simple boot_server at a CP.
@@ -53,6 +53,7 @@
bootp :: pid(), %% boot process
prim_state %% state for efile code loader
}).
+-type state() :: #state{}.
-define(single_addr_mask, {255, 255, 255, 255}).
@@ -165,6 +166,8 @@ member_address(_, []) ->
%% call-back functions.
%% ------------------------------------------------------------
+-spec init([atom()]) -> {'ok', state()}.
+
init(Slaves) ->
{ok, U} = gen_udp:open(?EBOOT_PORT, []),
{ok, L} = gen_tcp:listen(0, [binary,{packet,4}]),
@@ -176,15 +179,18 @@ init(Slaves) ->
Pid ! {Ref, L},
%% We trap exit inorder to restart boot_init and udp_port
process_flag(trap_exit, true),
- {ok, #state {priority = 0,
- version = erlang:system_info(version),
- udp_sock = U,
- udp_port = UPort,
- listen_sock = L,
- listen_port = Port,
- slaves = ordsets:from_list(Slaves),
- bootp = Pid
- }}.
+ {ok, #state{priority = 0,
+ version = erlang:system_info(version),
+ udp_sock = U,
+ udp_port = UPort,
+ listen_sock = L,
+ listen_port = Port,
+ slaves = ordsets:from_list(Slaves),
+ bootp = Pid
+ }}.
+
+-spec handle_call('which' | {'add',atom()} | {'delete',atom()}, _, state()) ->
+ {'reply', 'ok' | [atom()], state()}.
handle_call({add,Address}, _, S0) ->
Slaves = ordsets:add_element(Address, S0#state.slaves),
@@ -197,9 +203,13 @@ handle_call({delete,Address}, _, S0) ->
handle_call(which, _, S0) ->
{reply, ordsets:to_list(S0#state.slaves), S0}.
+-spec handle_cast(term(), [atom()]) -> {'noreply', [atom()]}.
+
handle_cast(_, Slaves) ->
{noreply, Slaves}.
+-spec handle_info(term(), state()) -> {'noreply', state()}.
+
handle_info({udp, U, IP, Port, Data}, S0) ->
Token = ?EBOOT_REQUEST ++ S0#state.version,
Valid = member_address(IP, ordsets:to_list(S0#state.slaves)),
@@ -230,9 +240,13 @@ handle_info({udp, U, IP, Port, Data}, S0) ->
handle_info(_Info, S0) ->
{noreply,S0}.
+-spec terminate(term(), state()) -> 'ok'.
+
terminate(_Reason, _S0) ->
ok.
+-spec code_change(term(), state(), term()) -> {'ok', state()}.
+
code_change(_Vsn, State, _Extra) ->
{ok, State}.
@@ -242,6 +256,8 @@ code_change(_Vsn, State, _Extra) ->
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec boot_init(reference()) -> no_return().
+
boot_init(Tag) ->
receive
{Tag, Listen} ->
diff --git a/lib/kernel/src/erl_epmd.erl b/lib/kernel/src/erl_epmd.erl
index e4b371836b..4a22637304 100644
--- a/lib/kernel/src/erl_epmd.erl
+++ b/lib/kernel/src/erl_epmd.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1998-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1998-2010. 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%
%%
-module(erl_epmd).
@@ -40,6 +40,7 @@
-import(lists, [reverse/1]).
-record(state, {socket, port_no = -1, name = ""}).
+-type state() :: #state{}.
-include("inet_int.hrl").
-include("erl_epmd.hrl").
@@ -111,11 +112,18 @@ register_node(Name, PortNo) ->
%%% Callback functions from gen_server
%%%----------------------------------------------------------------------
+-spec init(_) -> {'ok', state()}.
+
init(_) ->
{ok, #state{socket = -1}}.
%%----------------------------------------------------------------------
+-type calls() :: 'client_info_req' | 'stop' | {'register', term(), term()}.
+
+-spec handle_call(calls(), term(), state()) ->
+ {'reply', term(), state()} | {'stop', 'shutdown', 'ok', state()}.
+
handle_call({register, Name, PortNo}, _From, State) ->
case State#state.socket of
P when P < 0 ->
@@ -133,19 +141,23 @@ handle_call({register, Name, PortNo}, _From, State) ->
end;
handle_call(client_info_req, _From, State) ->
- Reply = {ok,{r4,State#state.name,State#state.port_no}},
- {reply,Reply,State};
+ Reply = {ok,{r4,State#state.name,State#state.port_no}},
+ {reply, Reply, State};
handle_call(stop, _From, State) ->
{stop, shutdown, ok, State}.
%%----------------------------------------------------------------------
+-spec handle_cast(term(), state()) -> {'noreply', state()}.
+
handle_cast(_, State) ->
{noreply, State}.
%%----------------------------------------------------------------------
+-spec handle_info(term(), state()) -> {'noreply', state()}.
+
handle_info({tcp_closed, Socket}, State) when State#state.socket =:= Socket ->
{noreply, State#state{socket = -1}};
handle_info(_, State) ->
@@ -153,6 +165,8 @@ handle_info(_, State) ->
%%----------------------------------------------------------------------
+-spec terminate(term(), state()) -> 'ok'.
+
terminate(_, #state{socket = Socket}) when Socket > 0 ->
close(Socket),
ok;
@@ -161,6 +175,8 @@ terminate(_, _) ->
%%----------------------------------------------------------------------
+-spec code_change(term(), state(), term()) -> {'ok', state()}.
+
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
diff --git a/lib/kernel/src/error_handler.erl b/lib/kernel/src/error_handler.erl
index 5f2507fc08..17dd02acd4 100644
--- a/lib/kernel/src/error_handler.erl
+++ b/lib/kernel/src/error_handler.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1996-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1996-2010. 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%
%%
-module(error_handler).
@@ -117,13 +117,13 @@ stub_function(Mod, Func, Args) ->
check_inheritance(Module, Args) ->
Attrs = erlang:get_module_info(Module, attributes),
- case lists:keysearch(extends, 1, Attrs) of
- {value,{extends,[Base]}} when is_atom(Base), Base =/= Module ->
+ case lists:keyfind(extends, 1, Attrs) of
+ {extends, [Base]} when is_atom(Base), Base =/= Module ->
%% This is just a heuristic for detecting abstract modules
%% with inheritance so they can be handled; it would be
%% much better to do it in the emulator runtime
- case lists:keysearch(abstract, 1, Attrs) of
- {value,{abstract,[true]}} ->
+ case lists:keyfind(abstract, 1, Attrs) of
+ {abstract, [true]} ->
case lists:reverse(Args) of
[M|Rs] when tuple_size(M) > 1,
element(1,M) =:= Module,
diff --git a/lib/kernel/src/file.erl b/lib/kernel/src/file.erl
index a42771dfb6..46ffa9d708 100644
--- a/lib/kernel/src/file.erl
+++ b/lib/kernel/src/file.erl
@@ -74,15 +74,22 @@
%% data types
-type filename() :: string().
-type file_info() :: #file_info{}.
--type io_device() :: pid() | #file_descriptor{}.
+-type fd() :: #file_descriptor{}.
+-type io_device() :: pid() | fd().
-type location() :: integer() | {'bof', integer()} | {'cur', integer()}
| {'eof', integer()} | 'bof' | 'cur' | 'eof'.
-type mode() :: 'read' | 'write' | 'append' | 'raw' | 'binary' |
{'delayed_write', non_neg_integer(), non_neg_integer()} |
'delayed_write' | {'read_ahead', pos_integer()} |
'read_ahead' | 'compressed'.
+-type name() :: string() | atom() | [name()].
+-type posix() :: atom().
-type bindings() :: any().
+-type date() :: {pos_integer(), pos_integer(), pos_integer()}.
+-type time() :: {non_neg_integer(), non_neg_integer(), non_neg_integer()}.
+-type date_time() :: {date(), time()}.
+
%%%-----------------------------------------------------------------
%%% General functions
diff --git a/lib/kernel/src/file_io_server.erl b/lib/kernel/src/file_io_server.erl
index 37e803c493..3ac35a209d 100644
--- a/lib/kernel/src/file_io_server.erl
+++ b/lib/kernel/src/file_io_server.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 2000-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 2000-2010. 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%
%%
-module(file_io_server).
@@ -106,21 +106,21 @@ do_start(Spawn, Owner, FileName, ModeList) ->
parse_options(List) ->
parse_options(expand_encoding(List), list, latin1, []).
-parse_options([],list,Uni,Acc) ->
+parse_options([], list, Uni, Acc) ->
{list,Uni,[binary|lists:reverse(Acc)]};
-parse_options([],binary,Uni,Acc) ->
+parse_options([], binary, Uni, Acc) ->
{binary,Uni,lists:reverse(Acc)};
-parse_options([{encoding, Encoding}|T],RMode,_,Acc) ->
+parse_options([{encoding, Encoding}|T], RMode, _, Acc) ->
case valid_enc(Encoding) of
{ok, ExpandedEnc} ->
- parse_options(T,RMode,ExpandedEnc,Acc);
- {error,Reason} ->
- {error,Reason}
+ parse_options(T, RMode, ExpandedEnc, Acc);
+ {error,_Reason} = Error ->
+ Error
end;
-parse_options([binary|T],_,Uni,Acc) ->
- parse_options(T,binary,Uni,[binary|Acc]);
-parse_options([H|T],R,U,Acc) ->
- parse_options(T,R,U,[H|Acc]).
+parse_options([binary|T], _, Uni, Acc) ->
+ parse_options(T, binary, Uni, [binary|Acc]);
+parse_options([H|T], R, U, Acc) ->
+ parse_options(T, R, U, [H|Acc]).
expand_encoding([]) ->
[];
@@ -153,7 +153,6 @@ valid_enc(_Other) ->
{error,badarg}.
-
server_loop(#state{mref = Mref} = State) ->
receive
{file_request, From, ReplyAs, Request} when is_pid(From) ->
@@ -326,7 +325,6 @@ io_request(Unknown,
{error,{error,Reason},State}.
-
%% Process a list of requests as long as the results are ok.
io_request_loop([], Result) ->
@@ -342,7 +340,6 @@ io_request_loop([Request|Tail],
io_request_loop(Tail, io_request(Request, State)).
-
%% I/O request put_chars
%%
put_chars(Chars, latin1, #state{handle=Handle, unic=latin1}=State) ->
@@ -653,20 +650,14 @@ do_setopts(Opts, State) ->
end.
getopts(#state{read_mode=RM, unic=Unic} = State) ->
- Bin = {binary, case RM of
- binary ->
- true;
- _ ->
- false
- end},
+ Bin = {binary, RM =:= binary},
Uni = {encoding, Unic},
{reply,[Bin,Uni],State}.
-
%% Concatenate two binaries and convert the result to list or binary
-cat(B1, B2, binary,latin1,latin1) ->
+cat(B1, B2, binary, latin1, latin1) ->
list_to_binary([B1,B2]);
-cat(B1, B2, binary,InEncoding,OutEncoding) ->
+cat(B1, B2, binary, InEncoding, OutEncoding) ->
case unicode:characters_to_binary([B1,B2],InEncoding,OutEncoding) of
Good when is_binary(Good) ->
Good;
diff --git a/lib/kernel/src/file_server.erl b/lib/kernel/src/file_server.erl
index 74f2fb94a9..64c61ba3ac 100644
--- a/lib/kernel/src/file_server.erl
+++ b/lib/kernel/src/file_server.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 2000-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 2000-2010. 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%
%%
@@ -62,6 +62,8 @@ stop() ->
%%% Callback functions from gen_server
%%%----------------------------------------------------------------------
+-type state() :: port(). % Internal type
+
%%----------------------------------------------------------------------
%% Func: init/1
%% Returns: {ok, State} |
@@ -69,6 +71,9 @@ stop() ->
%% ignore |
%% {stop, Reason}
%%----------------------------------------------------------------------
+
+-spec init([]) -> {'ok', state()} | {'stop', term()}.
+
init([]) ->
process_flag(trap_exit, true),
case ?PRIM_FILE:start() of
@@ -88,6 +93,12 @@ init([]) ->
%% {stop, Reason, Reply, State} | (terminate/2 is called)
%% {stop, Reason, State} (terminate/2 is called)
%%----------------------------------------------------------------------
+
+-spec handle_call(term(), term(), state()) ->
+ {'noreply', state()} |
+ {'reply', 'eof' | 'ok' | {'error', term()} | {'ok', term()}, state()} |
+ {'stop', 'normal', 'stopped', state()}.
+
handle_call({open, Name, ModeList}, {Pid, _Tag} = _From, Handle)
when is_list(ModeList) ->
Child = ?FILE_IO_SERVER:start_link(Pid, Name, ModeList),
@@ -190,6 +201,9 @@ handle_call(Request, From, Handle) ->
%% {noreply, State, Timeout} |
%% {stop, Reason, State} (terminate/2 is called)
%%----------------------------------------------------------------------
+
+-spec handle_cast(term(), state()) -> {'noreply', state()}.
+
handle_cast(Msg, State) ->
error_logger:error_msg("handle_cast(~p, _)", [Msg]),
{noreply, State}.
@@ -201,6 +215,9 @@ handle_cast(Msg, State) ->
%% {stop, Reason, State} (terminate/2 is called)
%%----------------------------------------------------------------------
+-spec handle_info(term(), state()) ->
+ {'noreply', state()} | {'stop', 'normal', state()}.
+
handle_info({'EXIT', Pid, _Reason}, Handle) when is_pid(Pid) ->
ets:delete(?FILE_IO_SERVER_TABLE, Pid),
{noreply, Handle};
@@ -219,6 +236,9 @@ handle_info(Info, State) ->
%% Purpose: Shutdown the server
%% Returns: any (ignored by gen_server)
%%----------------------------------------------------------------------
+
+-spec terminate(term(), state()) -> 'ok'.
+
terminate(_Reason, Handle) ->
?PRIM_FILE:stop(Handle).
@@ -227,6 +247,9 @@ terminate(_Reason, Handle) ->
%% Purpose: Convert process state when code is changed
%% Returns: {ok, NewState}
%%----------------------------------------------------------------------
+
+-spec code_change(term(), state(), term()) -> {'ok', state()}.
+
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
diff --git a/lib/kernel/src/global.erl b/lib/kernel/src/global.erl
index cc0402da73..081e7e2f93 100644
--- a/lib/kernel/src/global.erl
+++ b/lib/kernel/src/global.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1996-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1996-2010. 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%
%%
-module(global).
@@ -112,7 +112,7 @@
resolvers = [],
syncers = [] :: [pid()],
node_name = node() :: node(),
- the_locker, the_deleter, the_registrar, trace,
+ the_locker, the_registrar, trace,
global_lock_down = false
}).
@@ -153,6 +153,8 @@
%%% It can be removed later as can the deleter process.
%%% An extra process calling erlang:monitor() is sometimes created.
%%% The new_nodes messages has been augmented with the global lock id.
+%%%
+%%% R14A (OTP-8527): The deleter process has been removed.
start() ->
gen_server:start({local, global_name_server}, ?MODULE, [], []).
@@ -418,7 +420,6 @@ init([]) ->
S = #state{the_locker = start_the_locker(DoTrace),
trace = T0,
- the_deleter = start_the_deleter(self()),
the_registrar = start_the_registrar()},
S1 = trace_message(S, {init, node()}, []),
@@ -763,13 +764,16 @@ handle_cast({in_sync, Node, _IsKnown}, S) ->
%% Called when Pid on other node crashed
handle_cast({async_del_name, _Name, _Pid}, S) ->
- %% Sent from the_deleter at some node in the partition but node().
+ %% Sent from the_deleter at some node in the partition but node() (-R13B)
%% The DOWN message deletes the name.
+ %% R14A nodes and later do not send async_del_name messages.
{noreply, S};
handle_cast({async_del_lock, _ResourceId, _Pid}, S) ->
- %% Sent from global_name_server at some node in the partition but node().
+ %% Sent from global_name_server at some node in the partition but
+ %% node(). (-R13B)
%% The DOWN message deletes the lock.
+ %% R14A nodes and later do not send async_del_lock messages.
{noreply, S};
handle_cast(Request, S) ->
@@ -778,8 +782,6 @@ handle_cast(Request, S) ->
"handle_cast(~p, _)\n", [Request]),
{noreply, S}.
-handle_info({'EXIT', Deleter, _Reason}=Exit, #state{the_deleter=Deleter}=S) ->
- {stop, {deleter_died,Exit}, S#state{the_deleter=undefined}};
handle_info({'EXIT', Locker, _Reason}=Exit, #state{the_locker=Locker}=S) ->
{stop, {locker_died,Exit}, S#state{the_locker=undefined}};
handle_info({'EXIT', Registrar, _}=Exit, #state{the_registrar=Registrar}=S) ->
@@ -1348,30 +1350,13 @@ lock_still_set(PidOrNode, ExtraInfo, S) ->
[{?GLOBAL_RID, _LockReqId, PidRefs}] when is_pid(PidOrNode) ->
%% Name registration.
lists:keymember(PidOrNode, 1, PidRefs);
- [{?GLOBAL_RID, LockReqId, PidRefs}] when is_atom(PidOrNode) ->
- case extra_info(lock, ExtraInfo) of
- {?GLOBAL_RID, LockId} -> % R11B-4 or later
- LockReqId =:= LockId;
- undefined ->
- lock_still_set_old(PidOrNode, LockReqId, PidRefs)
- end;
+ [{?GLOBAL_RID, LockReqId, _PidRefs}] when is_atom(PidOrNode) ->
+ {?GLOBAL_RID, LockId} = extra_info(lock, ExtraInfo),
+ LockReqId =:= LockId;
[] ->
- %% If the global lock was not removed by a DOWN message
- %% then we have a node that do not monitor locking pids
- %% (pre R11B-3), or an R11B-3 node (which does not ensure
- %% that {new_nodes, ...} arrives before {del_lock, ...}).
not S#state.global_lock_down
end.
-%%% The following is probably overkill. It is possible that this node
-%%% has been locked again, but it is a rare occasion.
-lock_still_set_old(_Node, ReqId, _PidRefs) when is_pid(ReqId) ->
- %% Cannot do better than return true.
- true;
-lock_still_set_old(Node, ReqId, PidRefs) when is_list(ReqId) ->
- %% Connection, version > 4, but before R11B-4.
- [P || {P, _RPid, _Ref} <- PidRefs, node(P) =:= Node] =/= [].
-
extra_info(Tag, ExtraInfo) ->
%% ExtraInfo used to be a list of nodes (vsn 2).
case catch lists:keyfind(Tag, 1, ExtraInfo) of
@@ -1382,36 +1367,18 @@ extra_info(Tag, ExtraInfo) ->
end.
del_name(Ref, S) ->
- NameL = [{Name, Pid} ||
+ NameL = [Name ||
{_, Name} <- ets:lookup(global_pid_names, Ref),
- {_, Pid, _Method, _RPid, Ref1} <-
+ {_, _Pid, _Method, _RPid, Ref1} <-
ets:lookup(global_names, Name),
Ref1 =:= Ref],
- ?trace({async_del_name, self(), NameL, Ref}),
case NameL of
- [{Name, Pid}] ->
- _ = del_names(Name, Pid, S),
+ [Name] ->
delete_global_name2(Name, S);
[] ->
S
end.
-%% Send {async_del_name, ...} to old nodes (pre R11B-3).
-del_names(Name, Pid, S) ->
- Send = case ets:lookup(global_names_ext, Name) of
- [{Name, Pid, RegNode}] ->
- RegNode =:= node();
- [] ->
- node(Pid) =:= node()
- end,
- if
- Send ->
- ?trace({del_names, {pid,Pid}, {name,Name}}),
- S#state.the_deleter ! {delete_name, self(), Name, Pid};
- true ->
- ok
- end.
-
%% Keeps the entry in global_names for whereis_name/1.
delete_global_name_keep_pid(Name, S) ->
case ets:lookup(global_names, Name) of
@@ -1986,7 +1953,6 @@ pid_is_locking(Pid, PidRefs) ->
delete_lock(Ref, S0) ->
Locks = pid_locks(Ref),
- del_locks(Locks, Ref, S0#state.known),
F = fun({ResourceId, LockRequesterId, PidRefs}, S) ->
{Pid, _RPid, Ref} = lists:keyfind(Ref, 3, PidRefs),
remove_lock(ResourceId, LockRequesterId, Pid, PidRefs, true,S)
@@ -2003,20 +1969,6 @@ pid_locks(Ref) ->
rpid_is_locking(Ref, PidRefs) ->
lists:keyfind(Ref, 3, PidRefs) =/= false.
-%% Send {async_del_lock, ...} to old nodes (pre R11B-3).
-del_locks([{ResourceId, _LockReqId, PidRefs} | Tail], Ref, KnownNodes) ->
- {Pid, _RPid, Ref} = lists:keyfind(Ref, 3, PidRefs),
- case node(Pid) =:= node() of
- true ->
- gen_server:abcast(KnownNodes, global_name_server,
- {async_del_lock, ResourceId, Pid});
- false ->
- ok
- end,
- del_locks(Tail, Ref, KnownNodes);
-del_locks([], _Ref, _KnownNodes) ->
- ok.
-
handle_nodedown(Node, S) ->
%% DOWN signals from monitors have removed locks and registered names.
#state{known = Known, synced = Syncs} = S,
@@ -2147,51 +2099,6 @@ get_own_nodes() ->
OkTup
end.
-%%-----------------------------------------------------------------
-%% The deleter process is a satellite process to global_name_server
-%% that does background batch deleting of names when a process
-%% that had globally registered names dies. It is started by and
-%% linked to global_name_server.
-%%-----------------------------------------------------------------
-
-start_the_deleter(Global) ->
- spawn_link(fun() -> loop_the_deleter(Global) end).
-
-loop_the_deleter(Global) ->
- Deletions = collect_deletions(Global, []),
- ?trace({loop_the_deleter, self(), {deletions,Deletions},
- {names,get_names()}}),
- %% trans_all_known is called rather than trans/3 with nodes() as
- %% third argument. The reason is that known gets updated by
- %% new_nodes when the lock is still set. nodes() on the other hand
- %% could be updated later (if in_sync is received after the lock
- %% is gone). It is not likely that in_sync would be received after
- %% the lock has been taken here, but using trans_all_known makes it
- %% even less likely.
- trans_all_known(
- fun(Known) ->
- lists:map(
- fun({Name,Pid}) ->
- gen_server:abcast(Known, global_name_server,
- {async_del_name, Name, Pid})
- end, Deletions)
- end),
- loop_the_deleter(Global).
-
-collect_deletions(Global, Deletions) ->
- receive
- {delete_name, Global, Name, Pid} ->
- collect_deletions(Global, [{Name,Pid} | Deletions]);
- Other ->
- unexpected_message(Other, deleter),
- collect_deletions(Global, Deletions)
- after case Deletions of
- [] -> infinity;
- _ -> 0
- end ->
- lists:reverse(Deletions)
- end.
-
%% The registrar is a helper process that registers and unregisters
%% names. Since it never dies it assures that names are registered and
%% unregistered on all known nodes. It is started by and linked to
diff --git a/lib/kernel/src/group.erl b/lib/kernel/src/group.erl
index b770ab8386..f92c6f7208 100644
--- a/lib/kernel/src/group.erl
+++ b/lib/kernel/src/group.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1996-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1996-2010. 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%
%%
-module(group).
diff --git a/lib/kernel/src/heart.erl b/lib/kernel/src/heart.erl
index bad0950fca..e78acfc7a6 100644
--- a/lib/kernel/src/heart.erl
+++ b/lib/kernel/src/heart.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1996-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1996-2010. 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%
%%
-module(heart).
@@ -61,8 +61,8 @@ start() ->
wait_for_init_ack(From) ->
receive
- {ok, From} ->
- {ok, From};
+ {ok, From} = Ok ->
+ Ok;
{no_heart, From} ->
ignore;
{Error, From} ->
@@ -119,8 +119,7 @@ wait() ->
start_portprogram() ->
check_start_heart(),
- HeartCmd = "heart -pid " ++ os:getpid() ++ " " ++
- get_heart_timeouts(),
+ HeartCmd = "heart -pid " ++ os:getpid() ++ " " ++ get_heart_timeouts(),
try open_port({spawn, HeartCmd}, [{packet, 2}]) of
Port when is_port(Port) ->
case wait_ack(Port) of
@@ -175,7 +174,7 @@ wait_ack(Port) ->
loop(Parent, Port, Cmd) ->
send_heart_beat(Port),
receive
- {From, set_cmd, NewCmd} when is_list(NewCmd), length(NewCmd) < 2047 ->
+ {From, set_cmd, NewCmd} when length(NewCmd) < 2047 ->
send_heart_cmd(Port, NewCmd),
wait_ack(Port),
From ! {heart, ok},
diff --git a/lib/kernel/src/inet6_tcp_dist.erl b/lib/kernel/src/inet6_tcp_dist.erl
index 34cf582af7..fab00bbb9f 100644
--- a/lib/kernel/src/inet6_tcp_dist.erl
+++ b/lib/kernel/src/inet6_tcp_dist.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1997-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1997-2010. 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%
%%
-module(inet6_tcp_dist).
@@ -87,7 +87,7 @@ accept(Listen) ->
accept_loop(Kernel, Listen) ->
case inet6_tcp:accept(Listen) of
{ok, Socket} ->
- Kernel ! {accept,self(),Socket,inet,tcp},
+ Kernel ! {accept,self(),Socket,inet6,tcp},
controller(Kernel, Socket),
accept_loop(Kernel, Listen);
Error ->
@@ -236,8 +236,8 @@ do_setup(Kernel, Node, Type, MyNode, LongOrShortNames,SetupTime) ->
timer = Timer,
this_flags = 0,
other_version = Version,
- f_send = fun inet_tcp:send/2,
- f_recv = fun inet_tcp:recv/3,
+ f_send = fun inet6_tcp:send/2,
+ f_recv = fun inet6_tcp:recv/3,
f_setopts_pre_nodeup =
fun(S) ->
inet:setopts
@@ -262,7 +262,7 @@ do_setup(Kernel, Node, Type, MyNode, LongOrShortNames,SetupTime) ->
address = {Ip,TcpPort},
host = Address,
protocol = tcp,
- family = inet}
+ family = inet6}
end,
mf_tick = fun ?MODULE:tick/1,
mf_getstat = fun ?MODULE:getstat/1,
@@ -302,12 +302,17 @@ splitnode(Node, LongOrShortNames) ->
Host = lists:append(Tail),
case split_node(Host, $., []) of
[_] when LongOrShortNames =:= longnames ->
- error_msg("** System running to use "
- "fully qualified "
- "hostnames **~n"
- "** Hostname ~s is illegal **~n",
- [Host]),
- ?shutdown(Node);
+ case inet_parse:ipv6strict_address(Host) of
+ {ok, _} ->
+ [Name, Host];
+ _ ->
+ error_msg("** System running to use "
+ "fully qualified "
+ "hostnames **~n"
+ "** Hostname ~s is illegal **~n",
+ [Host]),
+ ?shutdown(Node)
+ end;
L when length(L) > 1, LongOrShortNames =:= shortnames ->
error_msg("** System NOT running to use fully qualified "
"hostnames **~n"
diff --git a/lib/kernel/src/inet_db.erl b/lib/kernel/src/inet_db.erl
index a05b380855..d4749b9756 100644
--- a/lib/kernel/src/inet_db.erl
+++ b/lib/kernel/src/inet_db.erl
@@ -88,6 +88,7 @@
hosts_file_byaddr, %% hosts table from system file
cache_timer %% timer reference for refresh
}).
+-type state() :: #state{}.
-include("inet.hrl").
-include("inet_int.hrl").
@@ -101,14 +102,14 @@
start() ->
case gen_server:start({local, inet_db}, inet_db, [], []) of
- {ok,Pid} -> inet_config:init(), {ok,Pid};
+ {ok, _Pid}=Ok -> inet_config:init(), Ok;
Error -> Error
end.
start_link() ->
case gen_server:start_link({local, inet_db}, inet_db, [], []) of
- {ok,Pid} -> inet_config:init(), {ok,Pid};
+ {ok, _Pid}=Ok -> inet_config:init(), Ok;
Error -> Error
end.
@@ -139,7 +140,6 @@ add_hosts(File) ->
Error -> Error
end.
-
add_host(IP, Names) -> call({add_host, IP, Names}).
del_host(IP) -> call({del_host, IP}).
@@ -481,10 +481,7 @@ res_check_option_absfile(F) ->
res_check_list([], _Fun) -> true;
res_check_list([H|T], Fun) ->
- case Fun(H) of
- true -> res_check_list(T, Fun);
- false -> false
- end;
+ Fun(H) andalso res_check_list(T, Fun);
res_check_list(_, _Fun) -> false.
res_check_ns({{A,B,C,D,E,F,G,H}, Port})
@@ -496,12 +493,12 @@ res_check_ns(_) -> false.
res_check_search("") -> true;
res_check_search(Dom) -> inet_parse:visible_string(Dom).
-socks_option(server) -> db_get(socks5_server);
-socks_option(port) -> db_get(socks5_port);
-socks_option(methods) -> db_get(socks5_methods);
-socks_option(noproxy) -> db_get(socks5_noproxy).
+socks_option(server) -> db_get(socks5_server);
+socks_option(port) -> db_get(socks5_port);
+socks_option(methods) -> db_get(socks5_methods);
+socks_option(noproxy) -> db_get(socks5_noproxy).
-gethostname() -> db_get(hostname).
+gethostname() -> db_get(hostname).
res_update_conf() ->
res_update(res_resolv_conf, res_resolv_conf_tm, res_resolv_conf_info,
@@ -590,15 +587,13 @@ getbyname(Name, Type) ->
getbysearch(Name, Dot, [Dom | Ds], Type, _) ->
case hostent_by_domain(Name ++ Dot ++ Dom, Type) of
- {ok, HEnt} -> {ok, HEnt};
- Error ->
- getbysearch(Name, Dot, Ds, Type, Error)
+ {ok, _HEnt}=Ok -> Ok;
+ Error -> getbysearch(Name, Dot, Ds, Type, Error)
end;
getbysearch(_Name, _Dot, [], _Type, Error) ->
Error.
-
%%
%% get_searchlist
%%
@@ -609,7 +604,6 @@ get_searchlist() ->
end.
-
make_hostent(Name, Addrs, Aliases, ?S_A) ->
#hostent {
h_name = Name,
@@ -844,6 +838,9 @@ lookup_socket(Socket) when is_port(Socket) ->
%% node_auth Ls - Default authenication
%% node_crypt Ls - Default encryption
%%
+
+-spec init([]) -> {'ok', state()}.
+
init([]) ->
process_flag(trap_exit, true),
Db = ets:new(inet_db, [public, named_table]),
@@ -897,6 +894,10 @@ reset_db(Db) ->
%% {stop, Reason, Reply, State} | (terminate/2 is called)
%% {stop, Reason, Reply, State} (terminate/2 is called)
%%----------------------------------------------------------------------
+
+-spec handle_call(term(), {pid(), term()}, state()) ->
+ {'reply', term(), state()} | {'stop', 'normal', 'ok', state()}.
+
handle_call(Request, From, #state{db=Db}=State) ->
case Request of
{load_hosts_file,IPNmAs} when is_list(IPNmAs) ->
@@ -1138,13 +1139,15 @@ handle_call(Request, From, #state{db=Db}=State) ->
{reply, error, State}
end.
-
%%----------------------------------------------------------------------
%% Func: handle_cast/2
%% Returns: {noreply, State} |
%% {noreply, State, Timeout} |
%% {stop, Reason, State} (terminate/2 is called)
%%----------------------------------------------------------------------
+
+-spec handle_cast(term(), state()) -> {'noreply', state()}.
+
handle_cast(_Msg, State) ->
{noreply, State}.
@@ -1154,6 +1157,9 @@ handle_cast(_Msg, State) ->
%% {noreply, State, Timeout} |
%% {stop, Reason, State} (terminate/2 is called)
%%----------------------------------------------------------------------
+
+-spec handle_info(term(), state()) -> {'noreply', state()}.
+
handle_info(refresh_timeout, State) ->
do_refresh_cache(State#state.cache),
{noreply, State#state{cache_timer = init_timer()}};
@@ -1166,6 +1172,9 @@ handle_info(_Info, State) ->
%% Purpose: Shutdown the server
%% Returns: any (ignored by gen_server)
%%----------------------------------------------------------------------
+
+-spec terminate(term(), state()) -> 'ok'.
+
terminate(_Reason, State) ->
stop_timer(State#state.cache_timer),
ok.
@@ -1342,16 +1351,15 @@ do_add_rr(RR, Db, State) ->
TM = times(),
case alloc_entry(Db, CacheDb, TM) of
true ->
- cache_rr(Db, CacheDb, RR#dns_rr { tm = TM,
- cnt = TM });
+ cache_rr(Db, CacheDb, RR#dns_rr{tm = TM, cnt = TM});
_ ->
false
end.
cache_rr(_Db, Cache, RR) ->
%% delete possible old entry
- ets:match_delete(Cache, RR#dns_rr { cnt = '_', tm = '_', ttl = '_',
- bm = '_', func = '_'}),
+ ets:match_delete(Cache, RR#dns_rr{cnt = '_', tm = '_', ttl = '_',
+ bm = '_', func = '_'}),
ets:insert(Cache, RR).
times() ->
@@ -1361,9 +1369,9 @@ times() ->
%% lookup and remove old entries
do_lookup_rr(Domain, Class, Type) ->
- match_rr(#dns_rr { domain = tolower(Domain), class = Class,type = Type,
- cnt = '_', tm = '_', ttl = '_',
- bm = '_', func = '_', data = '_'}).
+ match_rr(#dns_rr{domain = tolower(Domain), class = Class,type = Type,
+ cnt = '_', tm = '_', ttl = '_',
+ bm = '_', func = '_', data = '_'}).
match_rr(RR) ->
filter_rr(ets:match_object(inet_cache, RR), times()).
@@ -1414,7 +1422,7 @@ dn_in_addr_arpa(A,B,C,D) ->
integer_to_list(A) ++ ".in-addr.arpa".
dnib(X) ->
- [ hex(X), $., hex(X bsr 4), $., hex(X bsr 8), $., hex(X bsr 12), $.].
+ [hex(X), $., hex(X bsr 4), $., hex(X bsr 8), $., hex(X bsr 12), $.].
hex(X) ->
X4 = (X band 16#f),
@@ -1509,12 +1517,7 @@ alloc_entry(CacheDb, OldSize, TM, N) ->
delete_n_oldest(CacheDb, TM, OldestTM, N) ->
DelTM = trunc((TM - OldestTM) * 0.3) + OldestTM,
- case delete_older(CacheDb, DelTM, N) of
- 0 ->
- false;
- _ ->
- true
- end.
+ delete_older(CacheDb, DelTM, N) =/= 0.
%% Delete entries with latest access time older than TM.
%% Delete max N number of entries.
diff --git a/lib/kernel/src/inet_gethost_native.erl b/lib/kernel/src/inet_gethost_native.erl
index fabe9bf8b3..db3e44ce6f 100644
--- a/lib/kernel/src/inet_gethost_native.erl
+++ b/lib/kernel/src/inet_gethost_native.erl
@@ -106,8 +106,11 @@
pool_size = 4, % Number of C processes in pool.
statistics % Statistics record (records error causes).
}).
+-type state() :: #state{}.
%% The supervisor bridge code
+-spec init([]) -> {'ok', pid(), pid()} | {'error', term()}.
+
init([]) -> % Called by supervisor_bridge:start_link
Ref = make_ref(),
SaveTE = process_flag(trap_exit,true),
@@ -151,11 +154,13 @@ run_once() ->
{Port, {data, <<1:32, BinReply/binary>>}} ->
Pid ! {R, {ok, BinReply}}
after Timeout ->
- Pid ! {R,{error,timeout}}
+ Pid ! {R, {error, timeout}}
end.
-terminate(_Reason,Pid) ->
- (catch exit(Pid,kill)),
+-spec terminate(term(), pid()) -> 'ok'.
+
+terminate(_Reason, Pid) ->
+ (catch exit(Pid, kill)),
ok.
%%-----------------------------------------------------------------------
@@ -337,14 +342,14 @@ pick_client(State,RID,Clid) ->
{last, SoleClient}; % Note, not removed, the caller
% should cleanup request data
CList ->
- case lists:keysearch(Clid,1,CList) of
- {value, Client} ->
+ case lists:keyfind(Clid,1,CList) of
+ false ->
+ false;
+ Client ->
NCList = lists:keydelete(Clid,1,CList),
ets:insert(State#state.requests,
R#request{clients = NCList}),
- {more, Client};
- false ->
- false
+ {more, Client}
end
end
end.
@@ -382,8 +387,7 @@ restart_port(#state{port = Port, requests = Requests}) ->
end,
Requests),
NewPort.
-
-
+
do_open_port(Poolsize, ExtraArgs) ->
try
@@ -431,6 +435,7 @@ system_continue(_Parent, _, State) ->
system_terminate(Reason, _Parent, _, _State) ->
exit(Reason).
+-spec system_code_change(state(), module(), term(), term()) -> {'ok', state()}.
system_code_change(State, _Module, _OldVsn, _Extra) ->
{ok, State}. %% Nothing to do in this version.
diff --git a/lib/kernel/src/kernel_config.erl b/lib/kernel/src/kernel_config.erl
index e5e9a0498d..b1daf655c9 100644
--- a/lib/kernel/src/kernel_config.erl
+++ b/lib/kernel/src/kernel_config.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1996-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1996-2010. 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%
%%
-module(kernel_config).
@@ -40,6 +40,9 @@ start_link() -> gen_server:start_link(kernel_config, [], []).
%%-----------------------------------------------------------------
%% Callback functions from gen_server
%%-----------------------------------------------------------------
+
+-spec init([]) -> {'ok', []} | {'stop', term()}.
+
init([]) ->
process_flag(trap_exit, true),
case sync_nodes() of
@@ -59,18 +62,28 @@ init([]) ->
{stop, Error}
end.
+-spec handle_info(term(), State) -> {'noreply', State}.
+
handle_info(_, State) ->
{noreply, State}.
+-spec terminate(term(), term()) -> 'ok'.
+
terminate(_Reason, _State) ->
ok.
+-spec handle_call(term(), term(), State) -> {'reply', 'ok', State}.
+
handle_call('__not_used', _From, State) ->
{reply, ok, State}.
+-spec handle_cast(term(), State) -> {'noreply', State}.
+
handle_cast('__not_used', State) ->
{noreply, State}.
+-spec code_change(term(), State, term()) -> {'ok', State}.
+
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
@@ -79,9 +92,9 @@ code_change(_OldVsn, State, _Extra) ->
%%-----------------------------------------------------------------
sync_nodes() ->
case catch get_sync_data() of
- {error, Reason} ->
+ {error, Reason} = Error ->
error_logger:format("~p", [Reason]),
- {error, Reason};
+ Error;
{infinity, MandatoryNodes, OptionalNodes} ->
case wait_nodes(MandatoryNodes, OptionalNodes) of
ok ->
diff --git a/lib/kernel/src/os.erl b/lib/kernel/src/os.erl
index 196e6cdeb2..d0b498edc9 100644
--- a/lib/kernel/src/os.erl
+++ b/lib/kernel/src/os.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1997-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1997-2010. 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%
%%
-module(os).
@@ -169,6 +169,7 @@ unix_cmd(Cmd) ->
%% $1 parameter for easy identification of the resident shell.
%%
-define(SHELL, "/bin/sh -s unix:cmd 2>&1").
+-define(PORT_CREATOR_NAME, os_cmd_port_creator).
%%
%% Serializing open_port through a process to avoid smp lock contention
@@ -176,18 +177,37 @@ unix_cmd(Cmd) ->
%%
-spec start_port() -> port().
start_port() ->
- {Ref,Client} = {make_ref(),self()},
- try (os_cmd_port_creator ! {Ref,Client})
- catch
- error:_ -> spawn(fun() -> start_port_srv({Ref,Client}) end)
- end,
+ Ref = make_ref(),
+ Request = {Ref,self()},
+ {Pid, Mon} = case whereis(?PORT_CREATOR_NAME) of
+ undefined ->
+ spawn_monitor(fun() ->
+ start_port_srv(Request)
+ end);
+ P ->
+ P ! Request,
+ M = erlang:monitor(process, P),
+ {P, M}
+ end,
receive
- {Ref,Port} when is_port(Port) -> Port;
- {Ref,Error} -> exit(Error)
+ {Ref, Port} when is_port(Port) ->
+ erlang:demonitor(Mon, [flush]),
+ Port;
+ {Ref, Error} ->
+ erlang:demonitor(Mon, [flush]),
+ exit(Error);
+ {'DOWN', Mon, process, Pid, _Reason} ->
+ start_port()
end.
start_port_srv(Request) ->
- StayAlive = try register(os_cmd_port_creator, self())
+ %% We don't want a group leader of some random application. Use
+ %% kernel_sup's group leader.
+ {group_leader, GL} = process_info(whereis(kernel_sup),
+ group_leader),
+ true = group_leader(GL, self()),
+ process_flag(trap_exit, true),
+ StayAlive = try register(?PORT_CREATOR_NAME, self())
catch
error:_ -> false
end,
@@ -196,7 +216,7 @@ start_port_srv(Request) ->
start_port_srv_loop({Ref,Client}, StayAlive) ->
Reply = try open_port({spawn, ?SHELL},[stream]) of
Port when is_port(Port) ->
- port_connect(Port, Client),
+ (catch port_connect(Port, Client)),
unlink(Port),
Port
catch
@@ -205,10 +225,19 @@ start_port_srv_loop({Ref,Client}, StayAlive) ->
end,
Client ! {Ref,Reply},
case StayAlive of
- true -> start_port_srv_loop(receive Msg -> Msg end, true);
+ true -> start_port_srv_loop(get_open_port_request(), true);
false -> exiting
end.
+get_open_port_request() ->
+ receive
+ {Ref, Client} = Request when is_reference(Ref),
+ is_pid(Client) ->
+ Request;
+ _Junk ->
+ get_open_port_request()
+ end.
+
%%
%% unix_get_data(Port) -> Result
%%
diff --git a/lib/kernel/src/rpc.erl b/lib/kernel/src/rpc.erl
index d69f2a12ad..e09acb5024 100644
--- a/lib/kernel/src/rpc.erl
+++ b/lib/kernel/src/rpc.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1996-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1996-2010. 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%
%%
-module(rpc).
@@ -56,7 +56,7 @@
-export([safe_multi_server_call/2,safe_multi_server_call/3]).
%% gen_server exports
--export([init/1,handle_call/3,handle_cast/2,handle_info/2,
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
%% Internals
@@ -64,13 +64,23 @@
%%------------------------------------------------------------------------
+-type state() :: gb_tree().
+
+%%------------------------------------------------------------------------
+
%% Remote execution and broadcasting facility
+-spec start() -> {'ok', pid()} | 'ignore' | {'error', term()}.
+
start() ->
- gen_server:start({local,?NAME},?MODULE,[],[]).
+ gen_server:start({local,?NAME}, ?MODULE, [], []).
+
+-spec start_link() -> {'ok', pid()} | 'ignore' | {'error', term()}.
start_link() ->
- gen_server:start_link({local,?NAME},?MODULE,[],[]).
+ gen_server:start_link({local,?NAME}, ?MODULE, [], []).
+
+-spec stop() -> term().
stop() ->
stop(?NAME).
@@ -78,11 +88,17 @@ stop() ->
stop(Rpc) ->
gen_server:call(Rpc, stop, infinity).
--spec init([]) -> {'ok', gb_tree()}.
+-spec init([]) -> {'ok', state()}.
+
init([]) ->
process_flag(trap_exit, true),
{ok, gb_trees:empty()}.
+-spec handle_call(term(), term(), state()) ->
+ {'noreply', state()} |
+ {'reply', term(), state()} |
+ {'stop', 'normal', 'stopped', state()}.
+
handle_call({call, Mod, Fun, Args, Gleader}, To, S) ->
handle_call_call(Mod, Fun, Args, Gleader, To, S);
handle_call({block_call, Mod, Fun, Args, Gleader}, _To, S) ->
@@ -102,17 +118,18 @@ handle_call(stop, _To, S) ->
handle_call(_, _To, S) ->
{noreply, S}. % Ignore !
+-spec handle_cast(term(), state()) -> {'noreply', state()}.
handle_cast({cast, Mod, Fun, Args, Gleader}, S) ->
- spawn(
- fun() ->
- set_group_leader(Gleader),
- apply(Mod, Fun, Args)
- end),
- {noreply, S};
+ spawn(fun() ->
+ set_group_leader(Gleader),
+ apply(Mod, Fun, Args)
+ end),
+ {noreply, S};
handle_cast(_, S) ->
{noreply, S}. % Ignore !
+-spec handle_info(term(), state()) -> {'noreply', state()}.
handle_info({'DOWN', _, process, Caller, Reason}, S) ->
case gb_trees:lookup(Caller, S) of
@@ -145,7 +162,7 @@ handle_info({From, {sbcast, Name, Msg}}, S) ->
_ ->
From ! {?NAME, node(), node()}
end,
- {noreply,S};
+ {noreply, S};
handle_info({From, {send, Name, Msg}}, S) ->
case catch Name ! {From, Msg} of %% use catch to get the printout
{'EXIT', _} ->
@@ -153,16 +170,20 @@ handle_info({From, {send, Name, Msg}}, S) ->
_ ->
ok %% It's up to Name to respond !!!!!
end,
- {noreply,S};
+ {noreply, S};
handle_info({From, {call,Mod,Fun,Args,Gleader}}, S) ->
%% Special for hidden C node's, uugh ...
handle_call_call(Mod, Fun, Args, Gleader, {From,?NAME}, S);
handle_info(_, S) ->
- {noreply,S}.
+ {noreply, S}.
+
+-spec terminate(term(), state()) -> 'ok'.
terminate(_, _S) ->
ok.
+-spec code_change(term(), state(), term()) -> {'ok', state()}.
+
code_change(_, S, _) ->
{ok, S}.
@@ -209,7 +230,7 @@ proxy_user() ->
case whereis(rex_proxy_user) of
Pid when is_pid(Pid) -> Pid;
undefined ->
- Pid = spawn(fun()-> proxy_user_loop() end),
+ Pid = spawn(fun() -> proxy_user_loop() end),
try register(rex_proxy_user,Pid) of
true -> Pid
catch error:_ -> % spawn race, kill and try again
@@ -226,6 +247,8 @@ proxy_user_loop() ->
undefined -> proxy_user_loop()
end.
+-spec proxy_user_flush() -> no_return().
+
proxy_user_flush() ->
%% Forward all received messages to 'user'
receive Msg ->
diff --git a/lib/kernel/src/standard_error.erl b/lib/kernel/src/standard_error.erl
index 73901d9896..e41dcd01fc 100644
--- a/lib/kernel/src/standard_error.erl
+++ b/lib/kernel/src/standard_error.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 2009-2010. 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%
%%
-module(standard_error).
@@ -24,8 +24,6 @@
-define(NAME, standard_error).
-define(PROCNAME_SUP, standard_error_sup).
-%% Internal exports
--export([server/1, server/2]).
%% Defines for control ops
-define(CTRL_OP_GET_WINSIZE,100).
@@ -33,13 +31,19 @@
%%
%% The basic server and start-up.
%%
+-spec start_link() -> 'ignore' | {'error',term()} | {'ok',pid()}.
+
start_link() ->
supervisor_bridge:start_link({local, ?PROCNAME_SUP}, ?MODULE, []).
+-spec terminate(term(), pid()) -> 'ok'.
+
terminate(_Reason,Pid) ->
(catch exit(Pid,kill)),
ok.
+-spec init([]) -> {'error','no_stderror'} | {'ok',pid(),pid()}.
+
init([]) ->
case (catch start_port([out,binary])) of
Pid when is_pid(Pid) ->
@@ -48,18 +52,11 @@ init([]) ->
{error,no_stderror}
end.
-
start_port(PortSettings) ->
- Id = spawn(?MODULE,server,[{fd,2,2},PortSettings]),
- register(?NAME,Id),
+ Id = spawn(fun () -> server({fd,2,2}, PortSettings) end),
+ register(?NAME, Id),
Id.
-
-server(Pid) when is_pid(Pid) ->
- process_flag(trap_exit, true),
- link(Pid),
- run(Pid).
-
server(PortName,PortSettings) ->
process_flag(trap_exit, true),
Port = open_port(PortName,PortSettings),
@@ -82,17 +79,15 @@ server_loop(Port) ->
server_loop(Port)
end.
-
get_fd_geometry(Port) ->
case (catch port_control(Port,?CTRL_OP_GET_WINSIZE,[])) of
- List when is_list(List), length(List) =:= 8 ->
+ List when length(List) =:= 8 ->
<<W:32/native,H:32/native>> = list_to_binary(List),
{W,H};
_ ->
error
end.
-
%% NewSaveBuffer = io_request(Request, FromPid, ReplyAs, Port, SaveBuffer)
do_io_request(Req, From, ReplyAs, Port) ->
@@ -221,12 +216,7 @@ do_setopts(Opts, _Port) ->
{ok,ok}.
getopts(_Port) ->
- Uni = {unicode, case get(unicode) of
- true ->
- true;
- _ ->
- false
- end},
+ Uni = {unicode, get(unicode) =:= true},
{ok,[Uni]}.
wrap_characters_to_binary(Chars,From,To) ->
diff --git a/lib/kernel/src/user.erl b/lib/kernel/src/user.erl
index 17dc5a56a2..88f32df20b 100644
--- a/lib/kernel/src/user.erl
+++ b/lib/kernel/src/user.erl
@@ -26,9 +26,6 @@
-define(NAME, user).
-%% Internal exports
--export([server/1, server/2]).
-
%% Defines for control ops
-define(CTRL_OP_GET_WINSIZE,100).
@@ -43,7 +40,7 @@ start([Mod,Fun|Args]) ->
%% Mod,Fun,Args should return a pid. That process is supposed to act
%% as the io port.
Pid = apply(Mod, Fun, Args), % This better work!
- Id = spawn(?MODULE, server, [Pid]),
+ Id = spawn(fun() -> server(Pid) end),
register(?NAME, Id),
Id.
@@ -52,8 +49,8 @@ start_out() ->
start_port([out,binary]).
start_port(PortSettings) ->
- Id = spawn(?MODULE,server,[{fd,0,1},PortSettings]),
- register(?NAME,Id),
+ Id = spawn(fun() -> server({fd,0,1}, PortSettings) end),
+ register(?NAME, Id),
Id.
%% Return the pid of the shell process.
@@ -72,7 +69,6 @@ interfaces(User) ->
[]
end.
-
server(Pid) when is_pid(Pid) ->
process_flag(trap_exit, true),
link(Pid),
@@ -104,7 +100,7 @@ catch_loop(Port, Shell, Q) ->
new_shell ->
exit(Shell, kill),
catch_loop(Port, start_new_shell());
- {unknown_exit,{Shell,Reason},_} -> % shell has exited
+ {unknown_exit,{Shell,Reason},_} -> % shell has exited
case Reason of
normal ->
put_chars("*** ", Port, []);
@@ -172,7 +168,7 @@ server_loop(Port, Q) ->
get_fd_geometry(Port) ->
case (catch port_control(Port,?CTRL_OP_GET_WINSIZE,[])) of
- List when is_list(List), length(List) =:= 8 ->
+ List when length(List) =:= 8 ->
<<W:32/native,H:32/native>> = list_to_binary(List),
{W,H};
_ ->
@@ -373,12 +369,7 @@ do_setopts(Opts, _Port, Q) ->
end.
getopts(_Port,Q) ->
- Bin = {binary, case get(read_mode) of
- binary ->
- true;
- _ ->
- false
- end},
+ Bin = {binary, get(read_mode) =:= binary},
Uni = {encoding, case get(unicode) of
true ->
unicode;
diff --git a/lib/kernel/src/wrap_log_reader.erl b/lib/kernel/src/wrap_log_reader.erl
index 5030d3aed5..fabaa07752 100644
--- a/lib/kernel/src/wrap_log_reader.erl
+++ b/lib/kernel/src/wrap_log_reader.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1998-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1998-2010. 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%
%%
@@ -37,7 +37,7 @@
cont :: dlog_cont(), % disk_log's continuation record
file :: file:filename(), % file name without extension
file_no :: non_neg_integer(), % current file number
- mod_time :: date_time(), % modification time of current file
+ mod_time :: file:date_time(), % modification time of current file
first_no :: non_neg_integer() | 'one' % first read file number
}).
diff --git a/lib/kernel/test/code_SUITE.erl b/lib/kernel/test/code_SUITE.erl
index 37b9200942..08b6477c9d 100644
--- a/lib/kernel/test/code_SUITE.erl
+++ b/lib/kernel/test/code_SUITE.erl
@@ -543,8 +543,8 @@ add_del_path(Config) when is_list(Config) ->
?line code:del_path(Dir2),
?line PrivDir1 = code:priv_dir(dummy_app),
ok.
-
-
+
+
clash(Config) when is_list(Config) ->
DDir = ?config(data_dir,Config)++"clash/",
P = code:get_path(),
@@ -555,11 +555,11 @@ clash(Config) when is_list(Config) ->
?line true = code:del_path("."),
?line true = code:add_path(DDir++"foobar-0.1/ebin"),
?line true = code:add_path(DDir++"zork-0.8/ebin"),
- ?line test_server:capture_start(),
- ?line code:clash(),
- ?line test_server:capture_stop(),
- ?line OKMsg = test_server:capture_get(),
- ?line lists:prefix("** Found 0 name clashes in code paths", OKMsg),
+ test_server:capture_start(),
+ ?line ok = code:clash(),
+ test_server:capture_stop(),
+ ?line [OKMsg|_] = test_server:capture_get(),
+ ?line true = lists:prefix("** Found 0 name clashes", OKMsg),
?line true = code:set_path(P),
%% test clashing entries
@@ -568,13 +568,29 @@ clash(Config) when is_list(Config) ->
?line true = code:del_path("."),
?line true = code:add_path(DDir++"foobar-0.1/ebin"),
?line true = code:add_path(DDir++"foobar-0.1.ez/foobar-0.1/ebin"),
- ?line test_server:capture_start(),
- ?line code:clash(),
- ?line test_server:capture_stop(),
- ?line [ErrMsg1|_] = test_server:capture_get(),
- ?line {match, [" hides "]} = re:run(ErrMsg1, "\\*\\* .*( hides ).*",
+ test_server:capture_start(),
+ ?line ok = code:clash(),
+ test_server:capture_stop(),
+ ?line [ClashMsg|_] = test_server:capture_get(),
+ ?line {match, [" hides "]} = re:run(ClashMsg, "\\*\\* .*( hides ).*",
[{capture,all_but_first,list}]),
?line true = code:set_path(P),
+
+ %% test "Bad path can't read"
+
+ %% remove "." to prevent clash with test-server path
+ Priv = ?config(priv_dir, Config),
+ ?line true = code:del_path("."),
+ TmpEzFile = Priv++"foobar-0.tmp.ez",
+ ?line {ok, _} = file:copy(DDir++"foobar-0.1.ez", TmpEzFile),
+ ?line true = code:add_path(TmpEzFile++"/foobar-0.1/ebin"),
+ ?line ok = file:delete(TmpEzFile),
+ test_server:capture_start(),
+ ?line ok = code:clash(),
+ test_server:capture_stop(),
+ ?line [BadPathMsg|_] = test_server:capture_get(),
+ ?line true = lists:prefix("** Bad path can't read", BadPathMsg),
+ ?line true = code:set_path(P),
ok.
ext_mod_dep(suite) ->
diff --git a/lib/kernel/test/file_SUITE.erl b/lib/kernel/test/file_SUITE.erl
index d01e1f1fcf..1d170790a3 100644
--- a/lib/kernel/test/file_SUITE.erl
+++ b/lib/kernel/test/file_SUITE.erl
@@ -270,7 +270,10 @@ make_del_dir(Config) when is_list(Config) ->
%% Try deleting some bad directories
%% Deleting the parent directory to the current, sounds dangerous, huh?
%% Don't worry ;-) the parent directory should never be empty, right?
- ?line {error, eexist} = ?FILE_MODULE:del_dir('..'),
+ case ?FILE_MODULE:del_dir('..') of
+ {error, eexist} -> ok;
+ {error, einval} -> ok %FreeBSD
+ end,
?line {error, enoent} = ?FILE_MODULE:del_dir(""),
?line {error, badarg} = ?FILE_MODULE:del_dir([3,2,1,{}]),
diff --git a/lib/kernel/test/global_SUITE.erl b/lib/kernel/test/global_SUITE.erl
index a8c68985e2..7a84ad5e75 100644
--- a/lib/kernel/test/global_SUITE.erl
+++ b/lib/kernel/test/global_SUITE.erl
@@ -1,25 +1,23 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 1997-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 1997-2010. 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%
%%
-module(global_SUITE).
--compile(r11). % some code is run from r11-nodes
-
%-define(line_trace, 1).
-export([all/1,
@@ -2616,19 +2614,6 @@ proc(Parent) ->
name_exit(suite) -> [];
name_exit(doc) -> ["OTP-5563. Registered process dies."];
name_exit(Config) when is_list(Config) ->
- case ?t:is_release_available("r11b") of
- true ->
- StartOldFun =
- fun() ->
- {ok, N1} = start_node_rel(n_1, r11b, Config),
- {ok, N2} = start_node_rel(n_2, this, Config),
- [N1, N2]
- end,
- ?t:format("Test of r11~n"),
- do_name_exit(StartOldFun, old, Config);
- false ->
- ok
- end,
StartFun = fun() ->
{ok, N1} = start_node_rel(n_1, this, Config),
{ok, N2} = start_node_rel(n_2, this, Config),
@@ -2855,14 +2840,7 @@ many_nodes(Config) when is_list(Config) ->
N_nodes = quite_a_few_nodes(32),
{node_rel(1, N_nodes, this), N_nodes};
{unix, _} ->
- case ?t:is_release_available("r11b") of
- true ->
- This = node_rel(1, 16, this),
- R11B = node_rel(17, 32, r11b),
- {This ++ R11B, 32};
- false ->
- {node_rel(1, 32, this), 32}
- end;
+ {node_rel(1, 32, this), 32};
_ ->
{node_rel(1, 32, this), 32}
end,
@@ -3864,12 +3842,7 @@ start_node_rel(Name0, Rel, Config) ->
RelList ->
{RelList, ""}
end,
- Env = case Rel of
- r11b ->
- [{env, [{"ERL_R11B_FLAGS", []}]}];
- _ ->
- []
- end,
+ Env = [],
Pa = filename:dirname(code:which(?MODULE)),
Res = test_server:start_node(Name, peer,
[{args,
diff --git a/lib/kernel/test/inet_sockopt_SUITE_data/sockopt_helper.c b/lib/kernel/test/inet_sockopt_SUITE_data/sockopt_helper.c
index fb3c622909..f24c93edf5 100644
--- a/lib/kernel/test/inet_sockopt_SUITE_data/sockopt_helper.c
+++ b/lib/kernel/test/inet_sockopt_SUITE_data/sockopt_helper.c
@@ -1,4 +1,4 @@
-#if defined(VXWORKS) || defined(__OSE__)
+#if defined(VXWORKS)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/lib/kernel/test/os_SUITE.erl b/lib/kernel/test/os_SUITE.erl
index 1673b33010..6a3534b094 100644
--- a/lib/kernel/test/os_SUITE.erl
+++ b/lib/kernel/test/os_SUITE.erl
@@ -20,13 +20,13 @@
-export([all/1]).
-export([space_in_cwd/1, quoting/1, space_in_name/1, bad_command/1,
- find_executable/1, unix_comment_in_command/1]).
+ find_executable/1, unix_comment_in_command/1, evil/1]).
-include("test_server.hrl").
all(suite) ->
[space_in_cwd, quoting, space_in_name, bad_command, find_executable,
- unix_comment_in_command].
+ unix_comment_in_command, evil].
space_in_cwd(doc) ->
"Test that executing a command in a current working directory "
@@ -186,6 +186,48 @@ unix_comment_in_command(Config) when is_list(Config) ->
?line test_server:timetrap_cancel(Dog),
ok.
+-define(EVIL_PROCS, 100).
+-define(EVIL_LOOPS, 100).
+-define(PORT_CREATOR, os_cmd_port_creator).
+evil(Config) when is_list(Config) ->
+ Dog = test_server:timetrap(test_server:minutes(5)),
+ Parent = self(),
+ Ps = lists:map(fun (N) ->
+ spawn_link(fun () ->
+ evil_loop(Parent, ?EVIL_LOOPS,N)
+ end)
+ end, lists:seq(1, ?EVIL_PROCS)),
+ Devil = spawn(fun () -> devil(hd(Ps), hd(lists:reverse(Ps))) end),
+ lists:foreach(fun (P) -> receive {P, done} -> ok end end, Ps),
+ exit(Devil, kill),
+ test_server:timetrap_cancel(Dog),
+ ok.
+
+devil(P1, P2) ->
+ erlang:display({?PORT_CREATOR, whereis(?PORT_CREATOR)}),
+ (catch ?PORT_CREATOR ! lists:seq(1,1000000)),
+ (catch ?PORT_CREATOR ! lists:seq(1,666)),
+ (catch ?PORT_CREATOR ! grrrrrrrrrrrrrrrr),
+ (catch ?PORT_CREATOR ! {'EXIT', P1, buhuuu}),
+ (catch ?PORT_CREATOR ! {'EXIT', hd(erlang:ports()), buhuuu}),
+ (catch ?PORT_CREATOR ! {'EXIT', P2, arggggggg}),
+ receive after 500 -> ok end,
+ (catch exit(whereis(?PORT_CREATOR), kill)),
+ (catch ?PORT_CREATOR ! ">8|"),
+ receive after 500 -> ok end,
+ (catch exit(whereis(?PORT_CREATOR), diiiiiiiiiiiiiiiiiiiie)),
+ receive after 100 -> ok end,
+ devil(P1, P2).
+
+evil_loop(Parent, Loops, N) ->
+ Res = integer_to_list(N),
+ evil_loop(Parent, Loops, Res, "echo " ++ Res).
+
+evil_loop(Parent, 0, _Res, _Cmd) ->
+ Parent ! {self(), done};
+evil_loop(Parent, Loops, Res, Cmd) ->
+ comp(Res, os:cmd(Cmd)),
+ evil_loop(Parent, Loops-1, Res, Cmd).
comp(Expected, Got) ->
case strip_nl(Got) of
diff --git a/lib/kernel/test/prim_file_SUITE.erl b/lib/kernel/test/prim_file_SUITE.erl
index 860aeecbf4..6badbb5090 100644
--- a/lib/kernel/test/prim_file_SUITE.erl
+++ b/lib/kernel/test/prim_file_SUITE.erl
@@ -1,19 +1,19 @@
%%
%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 2000-2009. All Rights Reserved.
-%%
+%%
+%% Copyright Ericsson AB 2000-2010. 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%
%%
-module(prim_file_SUITE).
@@ -243,7 +243,10 @@ make_del_dir(Config, Handle, Suffix) ->
%% Try deleting some bad directories
%% Deleting the parent directory to the current, sounds dangerous, huh?
%% Don't worry ;-) the parent directory should never be empty, right?
- ?line {error, eexist} = ?PRIM_FILE_call(del_dir, Handle, [".."]),
+ case ?PRIM_FILE_call(del_dir, Handle, [".."]) of
+ {error, eexist} -> ok;
+ {error, einval} -> ok %FreeBSD
+ end,
?line {error, enoent} = ?PRIM_FILE_call(del_dir, Handle, [""]),
?line {error, badarg} = ?PRIM_FILE_call(del_dir, Handle, [[3,2,1,{}]]),