~ubuntu-branches/debian/wheezy/couchdb/wheezy

« back to all changes in this revision

Viewing changes to src/couch_inets/tftp_sup.erl

  • Committer: Bazaar Package Importer
  • Author(s): Noah Slater
  • Date: 2008-02-06 17:03:38 UTC
  • Revision ID: james.westby@ubuntu.com-20080206170338-y411anylx3oplqid
Tags: upstream-0.7.3~svn684
ImportĀ upstreamĀ versionĀ 0.7.3~svn684

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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/.
 
6
%% 
 
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
 
10
%% under the License.
 
11
%% 
 
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.''
 
15
%% 
 
16
%%     $Id$
 
17
%%
 
18
%%----------------------------------------------------------------------
 
19
%% Purpose: The top supervisor for tftp hangs under inets_sup.
 
20
%%----------------------------------------------------------------------
 
21
 
 
22
-module(tftp_sup).
 
23
 
 
24
-behaviour(supervisor).
 
25
 
 
26
%% API
 
27
-export([start_link/1]).
 
28
-export([start_child/1]).
 
29
 
 
30
%% Supervisor callback
 
31
-export([init/1]).
 
32
 
 
33
%%%=========================================================================
 
34
%%%  API
 
35
%%%=========================================================================
 
36
 
 
37
start_link(TftpServices) ->
 
38
    supervisor:start_link({local, ?MODULE}, ?MODULE, [TftpServices]).
 
39
 
 
40
start_child(Args) ->
 
41
    supervisor:start_child(?MODULE, Args).
 
42
    
 
43
%%%=========================================================================
 
44
%%%  Supervisor callback
 
45
%%%=========================================================================
 
46
 
 
47
init([Services]) when is_list(Services) ->
 
48
    RestartStrategy = one_for_one,
 
49
    MaxR = 10,
 
50
    MaxT = 3600,
 
51
    KillAfter = timer:seconds(3),
 
52
    Children = [worker_spec(KillAfter, Options) || {tftpd, Options} <- Services],
 
53
    {ok, {{RestartStrategy, MaxR, MaxT}, Children}}.
 
54
 
 
55
%%%=========================================================================
 
56
%%%  Internal functions
 
57
%%%=========================================================================
 
58
 
 
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}.
 
64
 
 
65
unique_name(Options) ->
 
66
    case lists:keysearch(port, 1, Options) of
 
67
        {value, {_, Port}} when is_integer(Port), Port > 0 -> 
 
68
            {tftpd, Port};
 
69
        _ ->
 
70
            {tftpd, erlang:now()}
 
71
    end.
 
72
 
 
73
%% supervisor_spec(Name) ->
 
74
%%     {Name, {Name, start, []}, permanent, infinity, supervisor,
 
75
%%      [Name, supervisor]}.
 
76
    
 
77
-ifdef(debug_shutdown).
 
78
supervisor_timeout(_KillAfter) -> timer:hours(24).
 
79
-else.
 
80
supervisor_timeout(KillAfter) -> KillAfter.
 
81
-endif.