mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-27 08:55:51 +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:
+41
-38
@@ -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 ->
|
||||||
@@ -79,14 +75,14 @@ let choose_xml_file = fun ?(multiple = false) title subdir cb ->
|
|||||||
dialog#add_select_button_stock `OPEN `OPEN ;
|
dialog#add_select_button_stock `OPEN `OPEN ;
|
||||||
dialog#set_select_multiple multiple;
|
dialog#set_select_multiple multiple;
|
||||||
begin match dialog#run (), dialog#filename with
|
begin match dialog#run (), dialog#filename with
|
||||||
| `OPEN, _ when multiple ->
|
| `OPEN, _ when multiple ->
|
||||||
let names = dialog#get_filenames in
|
let names = dialog#get_filenames in
|
||||||
dialog#destroy ();
|
dialog#destroy ();
|
||||||
cb (List.map (fun f -> subdir // strip_prefix dir f) names)
|
cb (List.map (fun f -> subdir // strip_prefix dir f) names)
|
||||||
| `OPEN, Some name ->
|
| `OPEN, Some name ->
|
||||||
dialog#destroy ();
|
dialog#destroy ();
|
||||||
cb [subdir // strip_prefix dir name]
|
cb [subdir // strip_prefix dir name]
|
||||||
| _ -> dialog#destroy ()
|
| _ -> dialog#destroy ()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -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
|
||||||
|
|
||||||
@@ -117,22 +113,29 @@ let run_and_monitor = fun ?(once = false) ?file gui log com_name com args ->
|
|||||||
|
|
||||||
let rec callback = fun stop ->
|
let rec callback = fun stop ->
|
||||||
match p#button_stop#label, stop with
|
match p#button_stop#label, stop with
|
||||||
"gtk-stop", _ ->
|
"gtk-stop", _ ->
|
||||||
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
|
||||||
p#button_stop#set_label "gtk-redo";
|
| (x, Unix.WEXITED 0) ->
|
||||||
p#button_remove#misc#set_sensitive true;
|
log (sprintf "\nDONE '%s'\n\n" com);
|
||||||
if once then
|
| (x, Unix.WEXITED i) ->
|
||||||
remove_callback ()
|
log (sprintf "\nFAILED '%s' with code %i\n\n" com i);
|
||||||
else if stop && p#checkbutton_autolaunch#active then
|
| (x, _) ->
|
||||||
callback false
|
log (sprintf "\nSTOPPED '%s'\n\n" com);
|
||||||
| "gtk-redo", false ->
|
end;
|
||||||
p#button_stop#set_label "gtk-stop";
|
p#button_stop#set_label "gtk-redo";
|
||||||
run callback;
|
p#button_remove#misc#set_sensitive true;
|
||||||
p#button_remove#misc#set_sensitive false
|
if once then
|
||||||
| _ -> ()
|
remove_callback ()
|
||||||
|
else if stop && p#checkbutton_autolaunch#active then
|
||||||
|
callback false
|
||||||
|
| "gtk-redo", false ->
|
||||||
|
p#button_stop#set_label "gtk-stop";
|
||||||
|
run callback;
|
||||||
|
p#button_remove#misc#set_sensitive false
|
||||||
|
| _ -> ()
|
||||||
in
|
in
|
||||||
ignore (p#button_stop#connect#clicked ~callback:(fun () -> callback false));
|
ignore (p#button_stop#connect#clicked ~callback:(fun () -> callback false));
|
||||||
ignore (p#entry_program#connect#activate ~callback:(fun () -> callback false));
|
ignore (p#entry_program#connect#activate ~callback:(fun () -> callback false));
|
||||||
@@ -160,8 +163,8 @@ let command = fun ?file gui (log:string->unit) ac_name target ->
|
|||||||
|
|
||||||
let conf_is_set = fun home ->
|
let conf_is_set = fun home ->
|
||||||
Sys.file_exists home &&
|
Sys.file_exists home &&
|
||||||
Sys.file_exists (home // "conf") &&
|
Sys.file_exists (home // "conf") &&
|
||||||
Sys.file_exists (home // "data")
|
Sys.file_exists (home // "data")
|
||||||
|
|
||||||
let druid = fun home ->
|
let druid = fun home ->
|
||||||
let w = GWindow.window ~title:"Configuring Paparazzi" () in
|
let w = GWindow.window ~title:"Configuring Paparazzi" () in
|
||||||
@@ -175,10 +178,10 @@ let druid = fun home ->
|
|||||||
fp#set_text (sprintf "Configuration files need to be installed in your Paparazzi home (%s). To use another directory, please exit this utility, set the PAPARAZZI_HOME variable to the desired folder and restart." home);
|
fp#set_text (sprintf "Configuration files need to be installed in your Paparazzi home (%s). To use another directory, please exit this utility, set the PAPARAZZI_HOME variable to the desired folder and restart." home);
|
||||||
d#append_page fp;
|
d#append_page fp;
|
||||||
ignore (fp#connect#next
|
ignore (fp#connect#next
|
||||||
(fun _ ->
|
(fun _ ->
|
||||||
basic_command prerr_endline "" "init";
|
basic_command prerr_endline "" "init";
|
||||||
false
|
false
|
||||||
))
|
))
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -188,10 +191,10 @@ let druid = fun home ->
|
|||||||
d#append_page ep ;
|
d#append_page ep ;
|
||||||
|
|
||||||
ignore (ep#connect#finish
|
ignore (ep#connect#finish
|
||||||
(fun _ ->
|
(fun _ ->
|
||||||
w#destroy ();
|
w#destroy ();
|
||||||
GMain.quit ()
|
GMain.quit ()
|
||||||
))
|
))
|
||||||
end;
|
end;
|
||||||
w#show ();
|
w#show ();
|
||||||
GMain.main ()
|
GMain.main ()
|
||||||
|
|||||||
Reference in New Issue
Block a user