close fd early, no need to carry file descriptors around
This commit is contained in:
parent
094922f6b0
commit
7b8f8fafbd
|
@ -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' ;
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) ;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue