]> xenbits.xensource.com Git - xcp/xen-api-libs.git/commitdiff
CA-46289: PIF_metrics vendor and devices names read incorrectly
authorRob Hoes <rob.hoes@citrix.com>
Tue, 12 Oct 2010 11:15:54 +0000 (12:15 +0100)
committerRob Hoes <rob.hoes@citrix.com>
Tue, 12 Oct 2010 11:15:54 +0000 (12:15 +0100)
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>
pciutil/pciutil.ml
stdext/unixext.ml
stdext/unixext.mli

index f157da85814d78c39531fc4853077131b336da59..00d46c3a1b21a3c088209a347c909e4c597e5101 100644 (file)
@@ -41,7 +41,7 @@ let parse_from file vendor device =
                                        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 (
index 3ac6864c0057cef052dfc4cb304d16516a35e3ae..14a266eb146af7997fa2aa90fc27503e88d118f2 100644 (file)
@@ -85,6 +85,8 @@ let daemonize () =
                end
        | _ -> exit 0
 
+exception Break
+
 let file_lines_fold f start file_path =
        let input = open_in file_path in
        let rec fold accumulator =
@@ -92,7 +94,7 @@ let file_lines_fold f start file_path =
                        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)
index f26d5453e5c4466049293e24cf4139720281ee0d..9664fc9d3e37603a5414a6f1db809aa9bf2c2f1e 100644 (file)
@@ -23,6 +23,9 @@ val daemonize : unit -> unit
 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