mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-02 21:37:24 +08:00
[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:
+13
-10
@@ -52,12 +52,8 @@ let run_and_log = fun log com ->
|
||||
if n = buf_size then log_input out
|
||||
in
|
||||
log_input com_stdout;
|
||||
if List.mem `IN ev then true
|
||||
else begin
|
||||
log (sprintf "\nDONE (%s)\n\n" com);
|
||||
false
|
||||
end in
|
||||
let io_watch_out = Glib.Io.add_watch [`IN; `HUP] cb channel_out in
|
||||
true in
|
||||
let io_watch_out = Glib.Io.add_watch [`IN] cb channel_out in
|
||||
pid, channel_out, com_stdout, io_watch_out
|
||||
|
||||
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
|
||||
let run = fun callback ->
|
||||
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 stop_cb_delay = 500 in (* ms *)
|
||||
pid := pi;
|
||||
outchan := unixfd;
|
||||
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
|
||||
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;
|
||||
close_in !outchan;
|
||||
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_remove#misc#set_sensitive true;
|
||||
if once then
|
||||
|
||||
Reference in New Issue
Block a user