From 99033bc070be6325ccbbb0a3e7e69396c8a30ec9 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Wed, 23 Mar 2011 16:07:03 +0100 Subject: Never fail when stopping rb, and fix file descriptor leak rb:stop did sometimes return {error,running}. This came from supervisor:delete_child and happened when the rb_server has not yet terminated when this function was called. Instead of having a separate gen_server call to rb_server for stopping the process, supervisor:terminate_child is now called. This is a synchronous function - i.e. it waits for the process to actually terminate before it returns. A file descriptor leak in rb:scan_files is corrected. The index file was never closed after reading. --- lib/sasl/src/rb.erl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib/sasl') diff --git a/lib/sasl/src/rb.erl b/lib/sasl/src/rb.erl index 13753565d8..500c795721 100644 --- a/lib/sasl/src/rb.erl +++ b/lib/sasl/src/rb.erl @@ -53,7 +53,7 @@ start_link(Options) -> gen_server:start_link({local, rb_server}, rb, Options, []). stop() -> - call(stop), + supervisor:terminate_child(sasl_sup, rb_server), supervisor:delete_child(sasl_sup, rb_server). rescan() -> rescan([]). @@ -205,8 +205,6 @@ handle_call({rescan, Options}, _From, State) -> NewState = State#state{data = Data, max = Max, type = Type, device = Device, abort = Abort, log = Log1}, {reply, ok, NewState}; -handle_call(stop, _From, State) -> - {stop, normal, stopped, State}; handle_call(_, _From, #state{data = undefined}) -> {reply, {error, no_data}, #state{}}; handle_call({list, Type}, _From, State) -> @@ -312,11 +310,14 @@ scan_files(RptDir, Max, Type) -> {ok, Fd} -> case catch file:read(Fd, 1) of {ok, [LastWritten]} -> + file:close(Fd), Files = make_file_list(RptDir, LastWritten), scan_files(RptDir, Files, Max, Type); - _ -> exit("cannot read the index file") + _X -> + file:close(Fd), + exit("cannot read the index file") end; - _ -> exit("cannot read the index file") + _X -> exit("cannot read the index file") end. make_file_list(Dir, FirstFileNo) -> -- cgit v1.2.3