a | b | |
---|
| 0 | + | diff --git a/src/couchdb/couch_os_process.erl b/src/couchdb/couch_os_process.erl |
---|
| 0 | + | index 3a267be..15e845b 100644 |
---|
| 0 | + | --- a/src/couchdb/couch_os_process.erl |
---|
| 0 | + | +++ b/src/couchdb/couch_os_process.erl |
---|
| 0 | + | @@ -20,7 +20,7 @@ |
---|
| 0 | + | |
---|
| 0 | + | -include("couch_db.hrl"). |
---|
| 0 | + | |
---|
| 0 | + | --define(PORT_OPTIONS, [stream, {line, 4096}, binary, exit_status, hide]). |
---|
| 0 | + | +-define(PORT_OPTIONS, [stream, {line, 1024}, binary, exit_status, hide]). |
---|
| 0 | + | |
---|
| 0 | + | -record(os_proc, |
---|
| 0 | + | {command, |
---|
| 0 | + | @@ -94,7 +94,7 @@ drop_port_messages(Port) -> |
---|
| 0 | + | % Utility functions for reading and writing |
---|
| 0 | + | % in custom functions |
---|
| 0 | + | writeline(OsProc, Data) when is_record(OsProc, os_proc) -> |
---|
| 0 | + | - port_command(OsProc#os_proc.port, [Data, $\n]). |
---|
| 0 | + | + port_command(OsProc#os_proc.port, [Data, $\r, $\n]). |
---|
| 0 | + | |
---|
| 0 | + | readline(#os_proc{} = OsProc) -> |
---|
| 0 | + | readline(OsProc, []). |
---|
| 0 | + | @@ -123,12 +123,12 @@ readline(#os_proc{port = Port} = OsProc, Acc) -> |
---|
| 0 | + | % Standard JSON functions |
---|
| 0 | + | writejson(OsProc, Data) when is_record(OsProc, os_proc) -> |
---|
| 0 | + | JsonData = ?JSON_ENCODE(Data), |
---|
| 0 | + | - ?LOG_DEBUG("OS Process ~p Input :: ~s", [OsProc#os_proc.port, JsonData]), |
---|
| 0 | + | + ?LOG_INFO("OS Process ~p Input :: ~s", [OsProc#os_proc.port, JsonData]), |
---|
| 0 | + | true = writeline(OsProc, JsonData). |
---|
| 0 | + | |
---|
| 0 | + | readjson(OsProc) when is_record(OsProc, os_proc) -> |
---|
| 0 | + | Line = iolist_to_binary(readline(OsProc)), |
---|
| 0 | + | - ?LOG_DEBUG("OS Process ~p Output :: ~s", [OsProc#os_proc.port, Line]), |
---|
| 0 | + | + ?LOG_INFO("OS Process ~p Output :: ~s", [OsProc#os_proc.port, Line]), |
---|
| 0 | + | try |
---|
| 0 | + | % Don't actually parse the whole JSON. Just try to see if it's |
---|
| 0 | + | % a command or a doc map/reduce/filter/show/list/update output. |
---|
| 0 | + | @@ -185,7 +185,7 @@ init([Command, Options, PortOptions]) -> |
---|
| 0 | + | }, |
---|
| 0 | + | KillCmd = iolist_to_binary(readline(BaseProc)), |
---|
| 0 | + | Pid = self(), |
---|
| 0 | + | - ?LOG_DEBUG("OS Process Start :: ~p", [BaseProc#os_proc.port]), |
---|
| 0 | + | + ?LOG_INFO("OS Process Start :: ~p", [BaseProc#os_proc.port]), |
---|
| 0 | + | spawn(fun() -> |
---|
| 0 | + | % this ensure the real os process is killed when this process dies. |
---|
| 0 | + | erlang:monitor(process, Pid), |
---|
| 0 | + | @@ -231,20 +231,20 @@ handle_cast({send, Data}, #os_proc{writer=Writer}=OsProc) -> |
---|
| 0 | + | {noreply, OsProc} |
---|
| 0 | + | catch |
---|
| 0 | + | throw:OsError -> |
---|
| 0 | + | - ?LOG_ERROR("Failed sending data: ~p -> ~p", [Data, OsError]), |
---|
| 0 | + | + ?LOG_INFO("Failed sending data: ~p -> ~p", [Data, OsError]), |
---|
| 0 | + | {stop, normal, OsProc} |
---|
| 0 | + | end; |
---|
| 0 | + | handle_cast(stop, OsProc) -> |
---|
| 0 | + | {stop, normal, OsProc}; |
---|
| 0 | + | handle_cast(Msg, OsProc) -> |
---|
| 0 | + | - ?LOG_DEBUG("OS Proc: Unknown cast: ~p", [Msg]), |
---|
| 0 | + | + ?LOG_INFO("OS Proc: Unknown cast: ~p", [Msg]), |
---|
| 0 | + | {noreply, OsProc}. |
---|
| 0 | + | |
---|
| 0 | + | handle_info({Port, {exit_status, 0}}, #os_proc{port=Port}=OsProc) -> |
---|
| 0 | + | ?LOG_INFO("OS Process terminated normally", []), |
---|
| 0 | + | {stop, normal, OsProc}; |
---|
| 0 | + | handle_info({Port, {exit_status, Status}}, #os_proc{port=Port}=OsProc) -> |
---|
| 0 | + | - ?LOG_ERROR("OS Process died with status: ~p", [Status]), |
---|
| 0 | + | + ?LOG_INFO("OS Process died with status: ~p", [Status]), |
---|
| 0 | + | {stop, {exit_status, Status}, OsProc}. |
---|
| 0 | + | |
---|
| 0 | + | code_change(_OldVsn, State, _Extra) -> |
---|
... | |
---|