[paparazzi_center] print better messages if commands exited with error

also got rid of the HUP handling in run_and_log, now only done in run_and_montior
closes #286
This commit is contained in:
Felix Ruess
2013-02-09 16:21:28 +01:00
parent cdf1ebfb36
commit d19179ea06
+13 -10
View File
@@ -52,12 +52,8 @@ let run_and_log = fun log com ->
if n = buf_size then log_input out if n = buf_size then log_input out
in in
log_input com_stdout; log_input com_stdout;
if List.mem `IN ev then true true in
else begin let io_watch_out = Glib.Io.add_watch [`IN] cb channel_out in
log (sprintf "\nDONE (%s)\n\n" com);
false
end in
let io_watch_out = Glib.Io.add_watch [`IN; `HUP] cb channel_out in
pid, channel_out, com_stdout, io_watch_out pid, channel_out, com_stdout, io_watch_out
let strip_prefix = fun dir file -> let strip_prefix = fun dir file ->
@@ -102,13 +98,13 @@ let run_and_monitor = fun ?(once = false) ?file gui log com_name com args ->
and watches = ref [] in and watches = ref [] in
let run = fun callback -> let run = fun callback ->
let c = p#entry_program#text in let c = p#entry_program#text in
log (sprintf "Run '%s'\n" c); log (sprintf "RUN '%s'\n" c);
let (pi, out, unixfd, io_watch) = run_and_log log ("exec "^c) in let (pi, out, unixfd, io_watch) = run_and_log log ("exec "^c) in
let stop_cb_delay = 500 in (* ms *)
pid := pi; pid := pi;
outchan := unixfd; outchan := unixfd;
let io_watch' = Glib.Io.add_watch [`HUP;`OUT] (fun _ -> let io_watch' = Glib.Io.add_watch [`HUP;`OUT] (fun _ ->
ignore (Glib.Timeout.add stop_cb_delay (fun () -> callback true; false)); (* call with a delay of 200ms, not strictly needed anymore, but seems more pleasing to the eye *)
ignore (Glib.Timeout.add 200 (fun () -> callback true; false));
false) out in false) out in
watches := [ io_watch; io_watch'] in watches := [ io_watch; io_watch'] in
@@ -121,7 +117,14 @@ let run_and_monitor = fun ?(once = false) ?file gui log com_name com args ->
List.iter Glib.Io.remove !watches; List.iter Glib.Io.remove !watches;
close_in !outchan; close_in !outchan;
ignore (Unix.kill !pid Sys.sigkill); ignore (Unix.kill !pid Sys.sigkill);
ignore (Unix.waitpid [] !pid); begin match Unix.waitpid [] !pid with
| (x, Unix.WEXITED 0) ->
log (sprintf "\nDONE '%s'\n\n" com);
| (x, Unix.WEXITED i) ->
log (sprintf "\nFAILED '%s' with code %i\n\n" com i);
| (x, _) ->
log (sprintf "\nSTOPPED '%s'\n\n" com);
end;
p#button_stop#set_label "gtk-redo"; p#button_stop#set_label "gtk-redo";
p#button_remove#misc#set_sensitive true; p#button_remove#misc#set_sensitive true;
if once then if once then