@@ -38,6 +38,32 @@ module StringSet = Set.Make(String)
3838
3939let log_exn_continue msg f x = try f x with e -> debug " Ignoring exception: %s while %s" (ExnHelper. string_of_exn e) msg
4040
41+ let call_script ?(log_successful_output =true ) ?env script args =
42+ try
43+ Unix. access script [ Unix. X_OK ];
44+ (* Use the same $PATH as xapi *)
45+ let env = match env with
46+ | None -> [| " PATH=" ^ (Sys. getenv " PATH" ) |]
47+ | Some env -> env
48+ in
49+ let output, _ = Forkhelpers. execute_command_get_output ~env script args in
50+ if log_successful_output then debug " %s %s succeeded [ output = '%s' ]" script (String. concat " " args) output;
51+ output
52+ with
53+ | Unix. Unix_error _ as e ->
54+ debug " Assuming script %s doesn't exist: caught %s" script (ExnHelper. string_of_exn e);
55+ raise e
56+ | Forkhelpers. Spawn_internal_error (stderr , stdout , status ) as e ->
57+ let message =
58+ match status with
59+ | Unix. WEXITED n -> Printf. sprintf " exited with code %d" n
60+ | Unix. WSIGNALED n -> Printf. sprintf " was killed by signal %d" n
61+ | Unix. WSTOPPED n -> Printf. sprintf " was stopped by signal %d" n
62+ in
63+ debug " %s %s %s [stdout = '%s'; stderr = '%s']" script (String. concat " " args)
64+ message stdout stderr;
65+ raise e
66+
4167(* * Construct a descriptive network name (used as name_label) for a give network interface. *)
4268let choose_network_name_for_pif device =
4369 Printf. sprintf " Pool-wide network associated with %s" device
@@ -200,11 +226,11 @@ let update_pif_address ~__context ~self =
200226let update_getty () =
201227 (* Running update-issue service on best effort basis *)
202228 try
203- ignore (Forkhelpers. execute_command_get_output ! Xapi_globs. update_issue_script [] );
204- ignore (Forkhelpers. execute_command_get_output ! Xapi_globs. kill_process_script [" -q" ; " -HUP" ; " mingetty" ; " agetty" ])
229+ ignore (call_script ~log_successful_output: false ! Xapi_globs. update_issue_script [] );
230+ ignore (call_script ~log_successful_output: false ! Xapi_globs. kill_process_script
231+ [" -q" ; " -HUP" ; " -r" ; " .*getty" ])
205232 with e ->
206- debug " update_getty at %s caught exception: %s"
207- __LOC__ (Printexc. to_string e)
233+ warn " Unable to update getty at %s" __LOC__
208234
209235let set_gateway ~__context ~pif ~bridge =
210236 let dbg = Context. string_of_task __context in
@@ -885,25 +911,6 @@ let on_oem ~__context =
885911
886912exception File_doesnt_exist of string
887913
888- let call_script ?(log_successful_output =true ) ?env script args =
889- try
890- Unix. access script [ Unix. X_OK ];
891- (* Use the same $PATH as xapi *)
892- let env = match env with
893- | None -> [| " PATH=" ^ (Sys. getenv " PATH" ) |]
894- | Some env -> env
895- in
896- let output, _ = Forkhelpers. execute_command_get_output ~env script args in
897- if log_successful_output then debug " %s %s succeeded [ output = '%s' ]" script (String. concat " " args) output;
898- output
899- with
900- | Unix. Unix_error _ as e ->
901- debug " Assuming script %s doesn't exist: caught %s" script (ExnHelper. string_of_exn e);
902- raise e
903- | Forkhelpers. Spawn_internal_error (stderr , stdout , Unix. WEXITED n ) as e ->
904- debug " %s %s exited with code %d [stdout = '%s'; stderr = '%s']" script (String. concat " " args) n stdout stderr;
905- raise e
906-
907914(* Repeatedly bisect a range to find the maximum value for which the monotonic function returns true *)
908915let rec bisect f lower upper =
909916 let ( /* ) = Int64. div and ( -* ) = Int64. sub and ( +* ) = Int64. add in
0 commit comments