diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2012-06-07 14:56:39 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2012-06-07 14:56:39 +0100 |
commit | 8c677526ea4ec7126f0e53d769ee2c63c3918411 (patch) | |
tree | 6e6a5176ed79f6bc9f3434fff55460686c53e15b | |
parent | 40b769597b02f3e5df03bb71ddef3511fbd91d4a (diff) | |
parent | 2471f4530305e0948e8a3113dfed6472131b05bf (diff) | |
download | rabbitmq-server-8c677526ea4ec7126f0e53d769ee2c63c3918411.tar.gz |
Merge bug 24982
-rw-r--r-- | src/rabbit_control_main.erl | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/rabbit_control_main.erl b/src/rabbit_control_main.erl index 4724555b..2e163cfb 100644 --- a/src/rabbit_control_main.erl +++ b/src/rabbit_control_main.erl @@ -490,12 +490,14 @@ wait_for_process_death(Pid) -> read_pid_file(PidFile, Wait) -> case {file:read_file(PidFile), Wait} of {{ok, Bin}, _} -> - S = string:strip(binary_to_list(Bin), right, $\n), - try list_to_integer(S) + S = binary_to_list(Bin), + {match, [PidS]} = re:run(S, "[^\\s]+", + [{capture, all, list}]), + try list_to_integer(PidS) catch error:badarg -> exit({error, {garbage_in_pid_file, PidFile}}) end, - S; + PidS; {{error, enoent}, true} -> timer:sleep(?EXTERNAL_CHECK_INTERVAL), read_pid_file(PidFile, Wait); @@ -507,8 +509,7 @@ read_pid_file(PidFile, Wait) -> % rpc:call(os, getpid, []) at this point process_up(Pid) -> with_os([{unix, fun () -> - system("ps -p " ++ Pid - ++ " >/dev/null 2>&1") =:= 0 + run_ps(Pid) =:= 0 end}, {win32, fun () -> Res = os:cmd("tasklist /nh /fi \"pid eq " ++ @@ -526,15 +527,17 @@ with_os(Handlers) -> Handler -> Handler() end. -% Like system(3) -system(Cmd) -> - ShCmd = "sh -c '" ++ escape_quotes(Cmd) ++ "'", - Port = erlang:open_port({spawn, ShCmd}, [exit_status,nouse_stdio]), - receive {Port, {exit_status, Status}} -> Status end. +run_ps(Pid) -> + Port = erlang:open_port({spawn, "ps -p " ++ Pid}, + [exit_status, {line, 16384}, + use_stdio, stderr_to_stdout]), + exit_loop(Port). -% Escape the quotes in a shell command so that it can be used in "sh -c 'cmd'" -escape_quotes(Cmd) -> - lists:flatten(lists:map(fun ($') -> "'\\''"; (Ch) -> Ch end, Cmd)). +exit_loop(Port) -> + receive + {Port, {exit_status, Rc}} -> Rc; + {Port, _} -> exit_loop(Port) + end. format_parse_error({_Line, Mod, Err}) -> lists:flatten(Mod:format_error(Err)). |