~rdoering/ubuntu/karmic/erlang/fix-535090

« back to all changes in this revision

Viewing changes to lib/ssh/src/ssh_subsystem_sup.erl

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090215164252-q5x4rcf8a5pbesb1
Tags: 1:12.b.5-dfsg-2
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%<copyright>
 
2
%% <year>2008-2008</year>
 
3
%% <holder>Ericsson AB, All Rights Reserved</holder>
 
4
%%</copyright>
 
5
%%<legalnotice>
 
6
%% The contents of this file are subject to the Erlang Public License,
 
7
%% Version 1.1, (the "License"); you may not use this file except in
 
8
%% compliance with the License. You should have received a copy of the
 
9
%% Erlang Public License along with this software. If not, it can be
 
10
%% retrieved online at http://www.erlang.org/.
 
11
%%
 
12
%% Software distributed under the License is distributed on an "AS IS"
 
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
%% the License for the specific language governing rights and limitations
 
15
%% under the License.
 
16
%%
 
17
%% The Initial Developer of the Original Code is Ericsson AB.
 
18
%%</legalnotice>
 
19
%%
 
20
%%----------------------------------------------------------------------
 
21
%% Purpose: The ssh subsystem supervisor 
 
22
%%----------------------------------------------------------------------
 
23
 
 
24
-module(ssh_subsystem_sup).
 
25
 
 
26
-behaviour(supervisor).
 
27
 
 
28
-export([start_link/1, connection_supervisor/1, channel_supervisor/1,
 
29
        connection_manager/1]).
 
30
 
 
31
%% Supervisor callback
 
32
-export([init/1]).
 
33
 
 
34
%%%=========================================================================
 
35
%%%  API
 
36
%%%=========================================================================
 
37
start_link(Opts) ->
 
38
    supervisor:start_link(?MODULE, [Opts]).
 
39
 
 
40
connection_manager(SubSystemSup) ->
 
41
    ConnectionSup = connection_supervisor(SubSystemSup),
 
42
    ssh_connection_sup:connection_manager(ConnectionSup).
 
43
 
 
44
connection_supervisor(SupPid) ->
 
45
    Children = supervisor:which_children(SupPid),
 
46
    ssh_connection_sup(Children).
 
47
 
 
48
channel_supervisor(SupPid) ->    
 
49
    Children = supervisor:which_children(SupPid),
 
50
    ssh_channel_sup(Children).
 
51
 
 
52
%%%=========================================================================
 
53
%%%  Supervisor callback
 
54
%%%=========================================================================
 
55
init([Opts]) ->
 
56
    RestartStrategy = one_for_all,
 
57
    MaxR = 10,
 
58
    MaxT = 3600,
 
59
    Children = child_specs(Opts),
 
60
    {ok, {{RestartStrategy, MaxR, MaxT}, Children}}.
 
61
 
 
62
%%%=========================================================================
 
63
%%%  Internal functions
 
64
%%%=========================================================================
 
65
child_specs(Opts) ->
 
66
    case proplists:get_value(role, Opts) of
 
67
        client ->               
 
68
            [ssh_connectinon_child_spec(Opts)];
 
69
        server ->
 
70
            [ssh_connectinon_child_spec(Opts), ssh_channel_child_spec(Opts)]
 
71
    end.
 
72
  
 
73
ssh_connectinon_child_spec(Opts) ->
 
74
    Address = proplists:get_value(address, Opts),
 
75
    Port = proplists:get_value(port, Opts),
 
76
    Role = proplists:get_value(role, Opts),
 
77
    Name = id(Role, ssh_connection_sup, Address, Port),
 
78
    StartFunc = {ssh_connection_sup, start_link, [Opts]},
 
79
    Restart = permanent, 
 
80
    Shutdown = infinity,
 
81
    Modules = [ssh_connection_sup],
 
82
    Type = supervisor,
 
83
    {Name, StartFunc, Restart, Shutdown, Type, Modules}.
 
84
 
 
85
ssh_channel_child_spec(Opts) ->
 
86
    Address = proplists:get_value(address, Opts),
 
87
    Port = proplists:get_value(port, Opts),
 
88
    Role = proplists:get_value(role, Opts),
 
89
    Name = id(Role, ssh_channel_sup, Address, Port),
 
90
    StartFunc = {ssh_channel_sup, start_link, [Opts]},
 
91
    Restart = permanent, 
 
92
    Shutdown = infinity,
 
93
    Modules = [ssh_channel_sup],
 
94
    Type = supervisor,
 
95
    {Name, StartFunc, Restart, Shutdown, Type, Modules}.
 
96
 
 
97
id(Role, Sup, Address, Port) ->
 
98
    {Role, Sup, Address, Port}.
 
99
 
 
100
ssh_connection_sup([{_, Child, _, [ssh_connection_sup]} | _]) ->
 
101
    Child;
 
102
ssh_connection_sup([_ | Rest]) ->
 
103
    ssh_connection_sup(Rest).
 
104
 
 
105
ssh_channel_sup([{_, Child, _, [ssh_channel_sup]} | _]) ->
 
106
    Child;
 
107
ssh_channel_sup([_ | Rest]) ->
 
108
    ssh_channel_sup(Rest).
 
109
 
 
110
 
 
111