From dfe6b5dddb13624323c5883381dedd34ad4a4663 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Improve output of --version, display readable error messages. --- virt-df/virt_df_main.ml | 60 ++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/virt-df/virt_df_main.ml b/virt-df/virt_df_main.ml index 57d002a..bcb798a 100644 --- a/virt-df/virt_df_main.ml +++ b/virt-df/virt_df_main.ml @@ -58,7 +58,7 @@ let () = let set_uri = function "" -> uri := None | u -> uri := Some u in let version () = - printf "virt-df %s\n" (Libvirt_version.version); + printf "virt-df %s\n" Virt_df_version.version; let major, minor, release = let v, _ = Libvirt.get_version () in @@ -136,31 +136,39 @@ OPTIONS" in ); exit 1 in - (* Get the list of active & inactive domains. *) - let doms = - let nr_active_doms = C.num_of_domains conn in - let active_doms = - Array.to_list (C.list_domains conn nr_active_doms) in - let active_doms = - List.map (D.lookup_by_id conn) active_doms in - if not !all then - active_doms - else ( - let nr_inactive_doms = C.num_of_defined_domains conn in - let inactive_doms = - Array.to_list (C.list_defined_domains conn nr_inactive_doms) in - let inactive_doms = - List.map (D.lookup_by_name conn) inactive_doms in - active_doms @ inactive_doms - ) in - - (* Get their XML. *) - let xmls = List.map (fun dom -> dom, D.get_xml_desc dom) doms in - - (* Parse the XML. *) - let xmls = List.map (fun (dom, xml) -> - dom, Xml.parse_string xml) xmls in - + let xmls = + try + (* Get the list of active & inactive domains. *) + let doms = + let nr_active_doms = C.num_of_domains conn in + let active_doms = + Array.to_list (C.list_domains conn nr_active_doms) in + let active_doms = + List.map (D.lookup_by_id conn) active_doms in + if not !all then + active_doms + else ( + let nr_inactive_doms = C.num_of_defined_domains conn in + let inactive_doms = + Array.to_list + (C.list_defined_domains conn nr_inactive_doms) in + let inactive_doms = + List.map (D.lookup_by_name conn) inactive_doms in + active_doms @ inactive_doms + ) in + + (* Get their XML. *) + let xmls = List.map (fun dom -> dom, D.get_xml_desc dom) doms in + + (* Parse the XML. *) + let xmls = List.map (fun (dom, xml) -> + dom, Xml.parse_string xml) xmls in + + xmls + with + Libvirt.Virterror err -> + prerr_endline (Libvirt.Virterror.to_string err); + exit 1 in xmls in (* Grr.. Need to use a library which has XPATH support (or cduce). *) -- 1.8.3.1