diff options
author | Piotr Dorobisz <piotr.dorobisz@erlang-solutions.com> | 2011-03-09 10:23:46 +0100 |
---|---|---|
committer | Henrik Nord <henrik@erlang.org> | 2011-08-30 15:22:16 +0200 |
commit | 80a78effcae7d20d86543081ae678bfe3316961f (patch) | |
tree | b007e0027a183e27dd59ead42044a078304b9fcc /lib/observer/src/ttb.erl | |
parent | 4c7786f58f8f101723b00e839baa068f8cf34579 (diff) | |
download | otp-80a78effcae7d20d86543081ae678bfe3316961f.tar.gz otp-80a78effcae7d20d86543081ae678bfe3316961f.tar.bz2 otp-80a78effcae7d20d86543081ae678bfe3316961f.zip |
BUGFIX stop([fetch]) crashes when the option {file,{local,F}} has been given
Diffstat (limited to 'lib/observer/src/ttb.erl')
-rw-r--r-- | lib/observer/src/ttb.erl | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/lib/observer/src/ttb.erl b/lib/observer/src/ttb.erl index 221b71df6a..7e2f835a08 100644 --- a/lib/observer/src/ttb.erl +++ b/lib/observer/src/ttb.erl @@ -459,13 +459,14 @@ stop() -> stop([]). stop(Opts) -> Fetch = stop_opts(Opts), - case whereis(?MODULE) of - undefined -> ok; - Pid when is_pid(Pid) -> - ?MODULE ! {stop,Fetch,self()}, - receive {?MODULE,stopped} -> ok end - end, - stopped. + Result = + case whereis(?MODULE) of + undefined -> ok; + Pid when is_pid(Pid) -> + ?MODULE ! {stop,Fetch,self()}, + receive {?MODULE,R} -> R end + end, + stop_return(Result,Opts). stop_opts(Opts) -> case lists:member(format,Opts) of @@ -478,6 +479,17 @@ stop_opts(Opts) -> end end. +stop_return(R,Opts) -> + case {lists:member(return,Opts),R} of + {true,_} -> + R; + {false,{stopped,_}} -> + stopped; + {false,_} -> + %% Anything other than 'stopped' would not be bw compatible... + stopped + end. + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Process implementation @@ -564,12 +576,13 @@ loop(NodeInfo) -> AllNodesAndMeta), ets:delete(?history_table), wait_for_fetch(AllNodes), - io:format("Stored logs in ~s~n",[filename:absname(Dir)]), + Absname = filename:absname(Dir), + io:format("Stored logs in ~s~n",[Absname]), case FetchOrFormat of format -> format(Dir); fetch -> ok end, - Sender ! {?MODULE,stopped} + Sender ! {?MODULE,{stopped,Absname}} ?get_status end. @@ -583,18 +596,17 @@ ts() -> [Y,M,D,H,Min,S]). - fetch(Localhost,Dir,Node,MetaFile) -> - case host(Node) of - Localhost -> % same host, just move the files - Files = rpc:call(Node,observer_backend,ttb_get_filenames,[MetaFile]), + case (host(Node) == Localhost) orelse is_local(MetaFile) of + true -> % same host, just move the files + Files = get_filenames(Node,MetaFile), lists:foreach( fun(File0) -> File = filename:join(Dir,filename:basename(File0)), file:rename(File0,File) end, Files); - _Otherhost -> + false -> {ok, LSock} = gen_tcp:listen(0, [binary,{packet,2},{active,false}]), {ok,Port} = inet:port(LSock), rpc:cast(Node,observer_backend,ttb_fetch, @@ -606,6 +618,16 @@ fetch(Localhost,Dir,Node,MetaFile) -> end, ?MODULE ! {fetch_complete,Node}. +is_local({local, _, _}) -> + true; +is_local(_) -> + false. + +get_filenames(_N, {local,F,_}) -> + observer_backend:ttb_get_filenames(F); +get_filenames(N, F) -> + rpc:call(N, observer_backend,ttb_get_filenames,[F]). + receive_files(Dir,Sock,Fd) -> case gen_tcp:recv(Sock, 0) of {ok, <<0,Bin/binary>>} -> |