From d19179ea06a4f2f6a54af2b4437f7d69a18fe4ea Mon Sep 17 00:00:00 2001 From: Felix Ruess Date: Sat, 9 Feb 2013 16:21:28 +0100 Subject: [PATCH] [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 --- sw/supervision/pc_common.ml | 79 +++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/sw/supervision/pc_common.ml b/sw/supervision/pc_common.ml index 43520622c8..74a6cd74e2 100644 --- a/sw/supervision/pc_common.ml +++ b/sw/supervision/pc_common.ml @@ -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 -> @@ -79,14 +75,14 @@ let choose_xml_file = fun ?(multiple = false) title subdir cb -> dialog#add_select_button_stock `OPEN `OPEN ; dialog#set_select_multiple multiple; begin match dialog#run (), dialog#filename with - | `OPEN, _ when multiple -> + | `OPEN, _ when multiple -> let names = dialog#get_filenames in dialog#destroy (); cb (List.map (fun f -> subdir // strip_prefix dir f) names) - | `OPEN, Some name -> + | `OPEN, Some name -> dialog#destroy (); cb [subdir // strip_prefix dir name] - | _ -> dialog#destroy () + | _ -> dialog#destroy () end @@ -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 @@ -117,22 +113,29 @@ let run_and_monitor = fun ?(once = false) ?file gui log com_name com args -> let rec callback = fun stop -> match p#button_stop#label, stop with - "gtk-stop", _ -> - List.iter Glib.Io.remove !watches; - close_in !outchan; - ignore (Unix.kill !pid Sys.sigkill); - ignore (Unix.waitpid [] !pid); - p#button_stop#set_label "gtk-redo"; - p#button_remove#misc#set_sensitive true; - 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 - | _ -> () + "gtk-stop", _ -> + List.iter Glib.Io.remove !watches; + close_in !outchan; + ignore (Unix.kill !pid Sys.sigkill); + 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 + 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 ignore (p#button_stop#connect#clicked ~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 -> Sys.file_exists home && - Sys.file_exists (home // "conf") && - Sys.file_exists (home // "data") + Sys.file_exists (home // "conf") && + Sys.file_exists (home // "data") let druid = fun home -> 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); d#append_page fp; ignore (fp#connect#next - (fun _ -> - basic_command prerr_endline "" "init"; - false - )) + (fun _ -> + basic_command prerr_endline "" "init"; + false + )) end; @@ -188,10 +191,10 @@ let druid = fun home -> d#append_page ep ; ignore (ep#connect#finish - (fun _ -> - w#destroy (); - GMain.quit () - )) + (fun _ -> + w#destroy (); + GMain.quit () + )) end; w#show (); GMain.main ()