1
%% ``The contents of this file are subject to the Erlang Public License,
2
%% Version 1.1, (the "License"); you may not use this file except in
3
%% compliance with the License. You should have received a copy of the
4
%% Erlang Public License along with this software. If not, it can be
5
%% retrieved via the world wide web at http://www.erlang.org/.
7
%% Software distributed under the License is distributed on an "AS IS"
8
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9
%% the License for the specific language governing rights and limitations
12
%% The Initial Developer of the Original Code is Ericsson Utvecklings AB.
13
%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
14
%% AB. All Rights Reserved.''
18
%%----------------------------------------------------------------------
19
%% Purpose: The top supervisor for tftp hangs under inets_sup.
20
%%----------------------------------------------------------------------
24
-behaviour(supervisor).
27
-export([start_link/1]).
28
-export([start_child/1]).
30
%% Supervisor callback
33
%%%=========================================================================
35
%%%=========================================================================
37
start_link(TftpServices) ->
38
supervisor:start_link({local, ?MODULE}, ?MODULE, [TftpServices]).
41
supervisor:start_child(?MODULE, Args).
43
%%%=========================================================================
44
%%% Supervisor callback
45
%%%=========================================================================
47
init([Services]) when is_list(Services) ->
48
RestartStrategy = one_for_one,
51
KillAfter = timer:seconds(3),
52
Children = [worker_spec(KillAfter, Options) || {tftpd, Options} <- Services],
53
{ok, {{RestartStrategy, MaxR, MaxT}, Children}}.
55
%%%=========================================================================
56
%%% Internal functions
57
%%%=========================================================================
59
worker_spec(KillAfter, Options) ->
60
Modules = [proc_lib, tftp, tftp_engine],
61
KA = supervisor_timeout(KillAfter),
62
Name = unique_name(Options),
63
{Name, {tftp, start, [Options]}, permanent, KA, worker, Modules}.
65
unique_name(Options) ->
66
case lists:keysearch(port, 1, Options) of
67
{value, {_, Port}} when is_integer(Port), Port > 0 ->
73
%% supervisor_spec(Name) ->
74
%% {Name, {Name, start, []}, permanent, infinity, supervisor,
75
%% [Name, supervisor]}.
77
-ifdef(debug_shutdown).
78
supervisor_timeout(_KillAfter) -> timer:hours(24).
80
supervisor_timeout(KillAfter) -> KillAfter.