Skip to content

Commit 7b4905f

Browse files
committed
Merge pull request #1918 from simonjbeaumont/ca-142533
CA-142533: Don't keep fd open for /dev/vga_arbiter
2 parents 8009546 + 8b0ec92 commit 7b4905f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ocaml/xapi/xapi_pci.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,12 @@ let update_pcis ~__context ~host =
154154

155155
let get_system_display_device () =
156156
try
157-
let device = Unix.openfile "/dev/vga_arbiter" [Unix.O_RDONLY] 0o000 in
158-
let data = Unixext.try_read_string ~limit:1024 device in
159-
let line = List.hd (String.split ~limit:2 '\n' data) in
157+
let line =
158+
Unixext.with_file "/dev/vga_arbiter" [Unix.O_RDONLY] 0o000 (fun fd ->
159+
let data = Unixext.try_read_string ~limit:1024 fd in
160+
List.hd (String.split ~limit:2 '\n' data)
161+
)
162+
in
160163
(* Example contents of line:
161164
* count:7,PCI:0000:10:00.0,decodes=io+mem,owns=io+mem,locks=none(0:0) *)
162165
let items = String.split ',' line in

0 commit comments

Comments
 (0)