Skip to content

Commit

Permalink
fixup! CP-48195: Instrument client side of forkexecd
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Buica <[email protected]>
  • Loading branch information
GabrielBuica committed Apr 29, 2024
1 parent 6bd2221 commit e800417
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions ocaml/forkexecd/lib/fecomms.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ let with_tracing ~tracing ~name f =
Tracing.with_tracing ~parent:tracing ~name f

let open_unix_domain_sock ?tracing () =
with_tracing ~tracing ~name:"open_unix_domain_sock" @@ fun _ ->
with_tracing ~tracing ~name:__FUNCTION__ @@ fun _ ->
Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0

let open_unix_domain_sock_server ?tracing path =
with_tracing ~tracing ~name:"open_unix_domain_sock_server" @@ fun tracing ->
with_tracing ~tracing ~name:__FUNCTION__ @@ fun tracing ->
Unixext.mkdir_rec (Filename.dirname path) 0o755 ;
Unixext.unlink_safe path ;
let sock = open_unix_domain_sock ?tracing () in
Expand All @@ -28,15 +28,15 @@ let open_unix_domain_sock_server ?tracing path =
with e -> Unix.close sock ; raise e

let open_unix_domain_sock_client ?tracing path =
with_tracing ~tracing ~name:"open_unix_domain_sock_client" @@ fun tracing ->
with_tracing ~tracing ~name:__FUNCTION__ @@ fun tracing ->
let sock = open_unix_domain_sock ?tracing () in
try
Unix.connect sock (Unix.ADDR_UNIX path) ;
sock
with e -> Unix.close sock ; raise e

let read_raw_rpc ?tracing sock =
with_tracing ~tracing ~name:"read_raw_rpc" @@ fun _ ->
with_tracing ~tracing ~name:__FUNCTION__ @@ fun _ ->
let buffer = Bytes.make 12 '\000' in
Unixext.really_read sock buffer 0 12 ;
let header = Bytes.unsafe_to_string buffer in
Expand All @@ -49,7 +49,7 @@ let read_raw_rpc ?tracing sock =
Error ("Header is not an integer: " ^ header)

let write_raw_rpc ?tracing sock ferpc =
with_tracing ~tracing ~name:"write_raw_rpc" @@ fun tracing ->
with_tracing ~tracing ~name:__FUNCTION__ @@ fun tracing ->
let ferpc = update_ferpc_env tracing ferpc in
let body = Jsonrpc.to_string (Fe.rpc_of_ferpc ferpc) in
let len = String.length body in
Expand All @@ -59,13 +59,13 @@ let write_raw_rpc ?tracing sock ferpc =
exception Connection_closed

let receive_named_fd ?tracing sock =
with_tracing ~tracing ~name:"receive_named_fd" @@ fun _ ->
with_tracing ~tracing ~name:__FUNCTION__ @@ fun _ ->
let buffer = Bytes.make 36 '\000' in
let len, _from, newfd = Unixext.recv_fd sock buffer 0 36 [] in
let buffer = Bytes.unsafe_to_string buffer in
if len = 0 then raise Connection_closed ;
(newfd, buffer)

let send_named_fd ?tracing sock uuid fd =
with_tracing ~tracing ~name:"send_named_fd" @@ fun _ ->
with_tracing ~tracing ~name:__FUNCTION__ @@ fun _ ->
ignore (Unixext.send_fd_substring sock uuid 0 (String.length uuid) [] fd)
12 changes: 6 additions & 6 deletions ocaml/forkexecd/lib/forkhelpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ let getpid (_sock, pid) = pid

type 'a result = Success of string * 'a | Failure of string * exn

let temp_dir_server = runtime_path ^ "/run/nonpersistent/forkexecd/"
let temp_dir_server =
Filename.concat runtime_path "/run/nonpersistent/forkexecd/"

let temp_dir =
try
Expand Down Expand Up @@ -185,10 +186,10 @@ type syslog_stdout =
let safe_close_and_exec ?tracing ?env stdin stdout stderr
(fds : (string * Unix.file_descr) list) ?(syslog_stdout = NoSyslogging)
?(redirect_stderr_to_stdout = false) (cmd : string) (args : string list) =
with_tracing ~tracing ~name:"safe_close_and_exec" @@ fun tracing ->
with_tracing ~tracing ~name:__FUNCTION__ @@ fun tracing ->
let sock =
Fecomms.open_unix_domain_sock_client ?tracing
(runtime_path ^ "/xapi/forker/main")
(Filename.concat runtime_path "/xapi/forker/main")
in
let stdinuuid = Uuidx.(to_string (make ())) in
let stdoutuuid = Uuidx.(to_string (make ())) in
Expand Down Expand Up @@ -373,14 +374,13 @@ let execute_command_get_output_inner ?tracing ?env ?stdin

let execute_command_get_output ?tracing ?env ?(syslog_stdout = NoSyslogging)
?(redirect_stderr_to_stdout = false) ?timeout cmd args =
with_tracing ~tracing ~name:"execute_command_get_output" @@ fun tracing ->
with_tracing ~tracing ~name:__FUNCTION__ @@ fun tracing ->
execute_command_get_output_inner ?tracing ?env ?stdin:None ?timeout
~syslog_stdout ~redirect_stderr_to_stdout cmd args

let execute_command_get_output_send_stdin ?tracing ?env
?(syslog_stdout = NoSyslogging) ?(redirect_stderr_to_stdout = false)
?timeout cmd args stdin =
with_tracing ~tracing ~name:"execute_command_get_output_send_stdin"
@@ fun tracing ->
with_tracing ~tracing ~name:__FUNCTION__ @@ fun tracing ->
execute_command_get_output_inner ?tracing ?env ~stdin ~syslog_stdout
~redirect_stderr_to_stdout ?timeout cmd args

0 comments on commit e800417

Please sign in to comment.