Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

""

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@835 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
commit 92d0dafae0678eeff06c740d26e70f34166a737f 1 parent 8d4d36f
@klacke authored
View
8 include/yaws.hrl
@@ -16,8 +16,9 @@
-define(GC_COPY_ERRLOG, 8).
-define(GC_BACKWARDS_COMPAT_PARSE, 16).
-define(GC_LOG_RESOLVE_HOSTNAME, 32).
+-define(GC_FAIL_ON_BIND_ERR, 64).
--define(GC_DEF, ?GC_AUTH_LOG).
+-define(GC_DEF, (?GC_AUTH_LOG bor ?GC_FAIL_ON_BIND_ERR)).
-define(gc_has_tty_trace(GC),
((GC#gconf.flags band ?GC_TTY_TRACE) /= 0)).
@@ -31,6 +32,8 @@
((GC#gconf.flags band ?GC_BACKWARDS_COMPAT_PARSE) /= 0)).
-define(gc_log_has_resolve_hostname(GC),
((GC#gconf.flags band ?GC_LOG_RESOLVE_HOSTNAME) /= 0)).
+-define(gc_fail_on_bind_err(GC),
+ ((GC#gconf.flags band ?GC_FAIL_ON_BIND_ERR) /= 0)).
-define(gc_set_tty_trace(GC, Bool),
@@ -47,6 +50,9 @@
-define(gc_log_set_resolve_hostname(GC, Bool),
GC#gconf{flags = yaws:flag(GC#gconf.flags, ?GC_LOG_RESOLVE_HOSTNAME, Bool)}).
+-define(gc_set_fail_on_bind_err(GC, Bool),
+ GC#gconf{flags = yaws:flag(GC#gconf.flags,?GC_FAIL_ON_BIND_ERR,Bool)}).
+
%% global conf
View
8 man/yaws.conf.5
@@ -103,11 +103,17 @@ is 1000000, 1 M. This value can changed.
.TP
-\B log_resolve_hostname = Boll\fR
+\B log_resolve_hostname = Bool\fR
By default the client host IP is not resolved in the access logs.
.TP
+\B fail_on_bind_err = Bool\fR
+Fail completely or not if yaws fails to bind a listen socket
+Default is true.
+
+
+.TP
\fB copy_error_log = true | false\fR
Enable or disable copying of the error log. When we run in
embedded mode, that may very well be some other systems process
View
11 scripts/yaws.conf.template
@@ -26,6 +26,8 @@ include_dir = %yawsdir%/examples/include
+
+
# This is a debug variable, possible values are http | traffic | false
# It is also possible to set the trace (possibly to the tty) while
# invoking yaws from the shell as in
@@ -35,6 +37,8 @@ trace = false
+
+
# it is possible to have yaws start additional
# application specific code at startup
#
@@ -60,6 +64,13 @@ log_wrap_size = 1000000
log_resolve_hostname = false
+
+# fail completely or not if yaws fails
+# to bind a listen socket
+fail_on_bind_err = true
+
+
+
# If yaws is started as root, it can, once it has opened
# all relevant sockets for listening, change the uid to a
# user with lower accessrights than root
View
15 src/yaws_config.erl
@@ -223,9 +223,11 @@ make_default_gconf(Debug) ->
30
end,
flags = if Debug ->
- ?GC_DEBUG bor ?GC_AUTH_LOG bor ?GC_COPY_ERRLOG;
+ ?GC_DEBUG bor ?GC_AUTH_LOG bor
+ ?GC_COPY_ERRLOG bor ?GC_FAIL_ON_BIND_ERR;
true ->
- ?GC_AUTH_LOG bor ?GC_COPY_ERRLOG
+ ?GC_AUTH_LOG bor ?GC_COPY_ERRLOG bor
+ ?GC_FAIL_ON_BIND_ERR
end,
uid = element(2, yaws:getuid()),
yaws = "Yaws " ++ yaws_vsn:version()}.
@@ -326,6 +328,15 @@ fload(FD, globals, GC, C, Cs, Lno, Chars) ->
{error, ?F("Expect true|false at line ~w", [Lno])}
end;
+ ["fail_on_bind_err", '=', Bool] ->
+ case is_bool(Bool) of
+ {true, Val} ->
+ fload(FD, globals, ?gc_set_fail_on_bind_err(GC, Val),
+ C, Cs, Lno+1, Next);
+ false ->
+ {error, ?F("Expect true|false at line ~w", [Lno])}
+ end;
+
["include_dir", '=', Incdir] ->
Dir = filename:absname(Incdir),
View
27 src/yaws_server.erl
@@ -190,13 +190,20 @@ init2(GC, Sconfs, RunMod, Embedded, FirstTime) ->
start_group(GC, Group) ->
- case proc_lib:start_link(?MODULE, gserv, [GC, Group]) of
+ FailOnBind = ?gc_fail_on_bind_err(GC),
+ case proc_lib:start_link(?MODULE, gserv, [self(), GC, Group]) of
+ {error, F, A} when FailOnBind == false ->
+ error_logger:error_msg(F, A),
+ false;
{error, F, A} ->
error_logger:error_msg(F, A),
+ erlang:fault(badbind);
+ {error, Reason} when FailOnBind == false ->
+ error_logger:error_msg("FATAL: ~p~n", [Reason]),
false;
{error, Reason} ->
error_logger:error_msg("FATAL: ~p~n", [Reason]),
- false;
+ erlang:fault(badbind);
{Pid, SCs} ->
{true, {Pid, SCs}};
none ->
@@ -386,14 +393,15 @@ set_dir_mode(Dir, Mode) ->
end.
-gserv(_, []) ->
+gserv(Top, _, []) ->
proc_lib:init_ack(none);
%% One server per IP we listen to
-gserv(GC, Group0) ->
+gserv(Top, GC, Group0) ->
process_flag(trap_exit, true),
?TC([{record, GC, gconf}]),
put(gc, GC),
+ put(top, Top),
Group = map(fun(SC) -> setup_ets(SC)
end, Group0),
SC = hd(Group),
@@ -487,8 +495,15 @@ gserv_loop(GS, Ready, Rnum, Last) ->
gserv_loop(GS2, [From | Ready], Rnum+1, Last)
end;
{'EXIT', _Pid, _} ->
- gserv_loop(GS, Ready, Rnum, Last);
-
+ case get(top) of
+ Pid ->
+ error_logger:format("Top proc died, terminate gserv",[]),
+ {links, Ls} = process_info(self(), links),
+ foreach(fun(X) -> unlink(X), exit(X, shutdown) end, Ls),
+ exit(noserver);
+ _ ->
+ gserv_loop(GS, Ready, Rnum, Last)
+ end;
{From, stop} ->
unlink(From),
{links, Ls} = process_info(self(), links),
Please sign in to comment.
Something went wrong with that request. Please try again.