vmmd_console: reuse ring if already present in map - this preserves console output between re-creations

This commit is contained in:
Hannes Mehnert 2019-01-27 12:55:23 +01:00
parent 943ea45e25
commit d9f76312ed
1 changed files with 9 additions and 6 deletions

View File

@ -69,15 +69,18 @@ let t = ref String.Map.empty
let add_fifo id =
let name = Vmm_core.Name.to_string id in
open_fifo id >|= function
| None -> Error (`Msg "opening")
| Some f ->
let ring = Vmm_ring.create "" () in
Logs.debug (fun m -> m "inserting fifo %s" name) ;
let map = String.Map.add name ring !t in
t := map ;
let ring = match String.Map.find name !t with
| None ->
let ring = Vmm_ring.create "" () in
let map = String.Map.add name ring !t in
t := map ;
ring
| Some ring -> ring
in
Lwt.async (read_console id name ring f) ;
Ok ()
| None ->
Error (`Msg "opening")
let subscribe s id =
let name = Vmm_core.Name.to_string id in