Skip to content

Commit

Permalink
Revert "albatross-console: remove closed fds on exceptions"
Browse files Browse the repository at this point in the history
This reverts commit 3c637ce.
  • Loading branch information
reynir committed Nov 20, 2024
1 parent a52cca7 commit 0066e18
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions daemon/albatross_console.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ let pp_unix_error ppf e = Fmt.string ppf (Unix.error_message e)
let active = ref Vmm_core.String_map.empty

let read_console id name ring fd =
let update s =
let s = Option.value ~default:[] s in
let s' = List.filter (fun (_v, _u, fd') -> fd != fd') s in
if s' = [] then
None
else
Some s'
in
Lwt.catch (fun () ->
Lwt_unix.wait_read fd >>= fun () ->
let channel = Lwt_io.of_fd ~mode:Lwt_io.Input fd in
Expand All @@ -44,6 +36,14 @@ let read_console id name ring fd =
Vmm_lwt.write_wire fd (header, data) >>= function
| Error _ ->
Vmm_lwt.safe_close fd >|= fun () ->
let update s =
let s = Option.value ~default:[] s in
let s' = List.filter (fun (_v, _u, fd') -> fd <> fd') s in
if s' = [] then
None
else
Some s'
in
active := Vmm_core.String_map.update name update !active
| Ok () -> Lwt.return_unit
in
Expand All @@ -61,8 +61,7 @@ let read_console id name ring fd =
| exn ->
Logs.err (fun m -> m "%s error while reading %s" name (Printexc.to_string exn))
end ;
Vmm_lwt.safe_close fd >|= fun () ->
active := Vmm_core.String_map.update name update !active)
Vmm_lwt.safe_close fd)

let open_fifo name =
let fifo = Vmm_core.Name.fifo_file name in
Expand Down

0 comments on commit 0066e18

Please sign in to comment.