diff --git a/app/vmmd.ml b/app/vmmd.ml index 4ae9236..7f6bd57 100644 --- a/app/vmmd.ml +++ b/app/vmmd.ml @@ -34,7 +34,7 @@ let create process cont = state := state'' ; s := { !s with vm_created = succ !s.vm_created } ; Lwt.async (fun () -> - Vmm_lwt.wait_and_clear vm.Unikernel.pid vm.Unikernel.stdout >>= fun r -> + Vmm_lwt.wait_and_clear vm.Unikernel.pid >>= fun r -> let state', out' = Vmm_vmmd.handle_shutdown !state name vm r in s := { !s with vm_destroyed = succ !s.vm_destroyed } ; state := state' ; diff --git a/src/vmm_core.ml b/src/vmm_core.ml index 189aa7b..76869c8 100644 --- a/src/vmm_core.ml +++ b/src/vmm_core.ml @@ -180,7 +180,6 @@ module Unikernel = struct cmd : Bos.Cmd.t ; pid : int ; taps : string list ; - stdout : Unix.file_descr (* ringbuffer thingy *) } let pp ppf vm = diff --git a/src/vmm_core.mli b/src/vmm_core.mli index b1d241a..7bffaa7 100644 --- a/src/vmm_core.mli +++ b/src/vmm_core.mli @@ -75,7 +75,6 @@ module Unikernel : sig cmd : Bos.Cmd.t; pid : int; taps : string list; - stdout : Unix.file_descr; } val pp : t Fmt.t diff --git a/src/vmm_lwt.ml b/src/vmm_lwt.ml index de66540..094a9a5 100644 --- a/src/vmm_lwt.ml +++ b/src/vmm_lwt.ml @@ -29,10 +29,9 @@ let rec waitpid pid = (Printexc.to_string e) pid) ; Lwt.return (Error ())) -let wait_and_clear pid stdout = +let wait_and_clear pid = Logs.debug (fun m -> m "waitpid() for pid %d" pid) ; waitpid pid >|= fun r -> - Vmm_unix.close_no_err stdout ; match r with | Error () -> Logs.err (fun m -> m "waitpid() for %d returned error" pid) ; diff --git a/src/vmm_lwt.mli b/src/vmm_lwt.mli index c4a9416..f47b169 100644 --- a/src/vmm_lwt.mli +++ b/src/vmm_lwt.mli @@ -8,7 +8,7 @@ val ret : Unix.process_status -> Vmm_core.process_exit val waitpid : int -> (int * Lwt_unix.process_status, unit) result Lwt.t -val wait_and_clear : int -> Unix.file_descr -> Vmm_core.process_exit Lwt.t +val wait_and_clear : int -> Vmm_core.process_exit Lwt.t val read_wire : Lwt_unix.file_descr -> (Vmm_commands.wire, [> `Eof | `Exception | `Toomuch ]) result Lwt.t diff --git a/src/vmm_unix.ml b/src/vmm_unix.ml index edb2974..bb5426c 100644 --- a/src/vmm_unix.ml +++ b/src/vmm_unix.ml @@ -37,10 +37,10 @@ let null = match read_fd_for_file (Fpath.v "/dev/null") with | Ok fd -> fd | Error _ -> invalid_arg "cannot read /dev/null" -let rec create_process prog args stdout stderr = - try Unix.create_process prog args null stdout stderr with +let rec create_process prog args stdout = + try Unix.create_process prog args null stdout stdout with | Unix.Unix_error (Unix.EINTR, _, _) -> - create_process prog args stdout stderr + create_process prog args stdout let rec close fd = try Unix.close fd with @@ -175,11 +175,14 @@ let exec name vm taps block = Logs.debug (fun m -> m "opened file descriptor!"); try Logs.debug (fun m -> m "creating process"); - let pid = create_process prog line stdout stdout in + let pid = create_process prog line stdout in Logs.debug (fun m -> m "created process %d: %a" pid Bos.Cmd.pp cmd) ; + (* we gave a copy (well, two copies) of that file descriptor to the solo5 + process and don't really need it here anymore... *) + close stdout ; (* this should get rid of the vmimage from vmmd's memory! *) let config = Unikernel.{ vm with image = (fst vm.Unikernel.image, Cstruct.create 0) } in - Ok Unikernel.{ config ; cmd ; pid ; taps ; stdout } + Ok Unikernel.{ config ; cmd ; pid ; taps } with Unix.Unix_error (e, _, _) -> close_no_err stdout;