diff options
author | Ingela Anderton Andin <[email protected]> | 2015-06-29 15:17:02 +0200 |
---|---|---|
committer | Ingela Anderton Andin <[email protected]> | 2015-07-01 14:36:04 +0200 |
commit | ca166cb0b7a7202b1f923e7c84848071a7c29efc (patch) | |
tree | d7a8222ad2799ae430b9e53c6902dbdaf5361e1a | |
parent | 0f3f8f5871a1ea503cc80ae17adc8dec96c79445 (diff) | |
download | otp-ca166cb0b7a7202b1f923e7c84848071a7c29efc.tar.gz otp-ca166cb0b7a7202b1f923e7c84848071a7c29efc.tar.bz2 otp-ca166cb0b7a7202b1f923e7c84848071a7c29efc.zip |
inets: Fix broken fd feature
If a wrapper script is used to open a privileged port before starting
erlang and supplied as a init argument to erlang it should override
the port configured by the httpd config file. Some of the code handling
this was lost, in the commit da3797589463002f28fc42ef27872650fe1de938,
due to missing tests of this functionality.
This commit adds the code for this in a better place.
In 18 also add a test.
-rw-r--r-- | lib/inets/src/http_server/httpd_sup.erl | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/lib/inets/src/http_server/httpd_sup.erl b/lib/inets/src/http_server/httpd_sup.erl index da641cf533..75a65fd576 100644 --- a/lib/inets/src/http_server/httpd_sup.erl +++ b/lib/inets/src/http_server/httpd_sup.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2014. All Rights Reserved. +%% Copyright Ericsson AB 2004-2015. 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 @@ -196,12 +196,16 @@ httpd_child_spec(ConfigFile, AcceptTimeoutDef, DebugDef) -> end. httpd_child_spec(Config, AcceptTimeout, Debug, Addr, Port) -> - Fd = proplists:get_value(fd, Config, undefined), - case Port == 0 orelse Fd =/= undefined of - true -> - httpd_child_spec_listen(Config, AcceptTimeout, Debug, Addr, Port); - false -> - httpd_child_spec_nolisten(Config, AcceptTimeout, Debug, Addr, Port) + case get_fd(Port) of + {ok, Fd} -> + case Port == 0 orelse Fd =/= undefined of + true -> + httpd_child_spec_listen(Config, AcceptTimeout, Debug, Addr, Port); + false -> + httpd_child_spec_nolisten(Config, AcceptTimeout, Debug, Addr, Port) + end; + Error -> + Error end. httpd_child_spec_listen(Config, AcceptTimeout, Debug, Addr, Port) -> @@ -247,7 +251,7 @@ listen(Address, Port, Config) -> SocketType -> case http_transport:start(SocketType) of ok -> - Fd = proplists:get_value(fd, Config), + {ok, Fd} = get_fd(Port), IpFamily = proplists:get_value(ipfamily, Config, inet6fb4), case http_transport:listen(SocketType, Address, Port, Fd, IpFamily) of {ok, ListenSocket} -> @@ -366,3 +370,19 @@ ssl_ca_certificate_file(Config) -> File -> [{cacertfile, File}] end. + +get_fd(0) -> + {ok, undefined}; +get_fd(Port) -> + FdKey = list_to_atom("httpd_" ++ integer_to_list(Port)), + case init:get_argument(FdKey) of + {ok, [[Value]]} -> + case (catch list_to_integer(Value)) of + N when is_integer(N) -> + {ok, N}; + _ -> + {error, {bad_descriptor, Value}} + end; + _ -> + {ok, undefined} + end. |