PIF vendor and device names were listed as "unknown" in the PIF_metrics. This was due to a recent change in the Unixext.readfile_line function in combination with a slightly dubious way of jumping out of the read loop by raising End_of_file in pciutil.ml.
It is now possible to raise Unixext.Break in the function passed to Unixext.readfile_line, to break out of the read loop (if you really want to).
Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
if xdevice = device then (
device_str := Some (String.sub line 7 (String.length line - 7));
(* abort reading, we found what we want *)
- raise End_of_file
+ raise Unixext.Break
)
)
) else (
end
| _ -> exit 0
+exception Break
+
let file_lines_fold f start file_path =
let input = open_in file_path in
let rec fold accumulator =
try Some (input_line input)
with End_of_file -> None in
match line with
- | Some line -> fold (f accumulator line)
+ | Some line -> (try fold (f accumulator line) with Break -> accumulator)
| None -> accumulator in
finally
(fun () -> fold start)
val with_file : string -> Unix.open_flag list -> Unix.file_perm -> (Unix.file_descr -> 'a) -> 'a
val with_directory : string -> (Unix.dir_handle -> 'a) -> 'a
+(** Exception to be raised in function to break out of [file_lines_fold]. *)
+exception Break
+
(** Folds function [f] over every line in the file at [file_path] using the
starting value [start]. *)
val file_lines_fold : ('a -> string -> 'a) -> 'a -> string -> 'a