Skip to content

Commit

Permalink
[sw/supervision] paparazzi center: use input_line to read one line at…
Browse files Browse the repository at this point in the history
… a time

* this should make error/warning/info coloration work properly
* on HUP signal just recursively read into a small buffer like we did before,
  since we might not get a newline at the end...
should fix #113
  • Loading branch information
flixr committed Sep 12, 2012
1 parent 588331d commit 65ac431
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions sw/supervision/pc_common.ml
Expand Up @@ -37,14 +37,19 @@ let my_open_process_in = fun cmd ->
Unix.close in_write;
pid, inchan

let buf_size = 1024
let buf_size = 128

let run_and_log = fun log com ->
let com = com ^ " 2>&1" in
let pid, com_stdout = my_open_process_in com in
let channel_out = GMain.Io.channel_of_descr (Unix.descr_of_in_channel com_stdout) in
let cb = fun ev ->
if List.mem `IN ev then begin
(* read one line, add the newline again and log it *)
let line = input_line com_stdout in
log (line ^ "\n");
true
end else begin
let buf = String.create buf_size in
(* loop until input returns zero *)
let rec log_input = fun out ->
Expand All @@ -56,8 +61,6 @@ let run_and_log = fun log com ->
end;
in
log_input com_stdout;
true
end else begin
log (sprintf "\nDONE (%s)\n\n" com);
false
end in
Expand Down

0 comments on commit 65ac431

Please sign in to comment.