From: David Scott Date: Tue, 12 Oct 2010 09:33:26 +0000 (+0100) Subject: CA-44731: replace uses of read_whole_file_to_string with string_of_file X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=d2ca1aad4c9c1e42b403c66bb3b0fdc7c5acec32;p=xcp%2Fxen-api.git CA-44731: replace uses of read_whole_file_to_string with string_of_file Signed-off-by: David Scott --- diff --git a/ocaml/database/db_cache_types.ml b/ocaml/database/db_cache_types.ml index f150d090..d22fc2b0 100644 --- a/ocaml/database/db_cache_types.ml +++ b/ocaml/database/db_cache_types.ml @@ -46,8 +46,8 @@ let gen_manifest gen_count = { installation_uuid = Xapi_inventory.lookup Xapi_inventory._installation_uuid; control_domain_uuid = Xapi_inventory.lookup Xapi_inventory._control_domain_uuid; - pool_conf = Unixext.read_whole_file_to_string Xapi_globs.pool_config_file; - pool_token = Unixext.read_whole_file_to_string Xapi_globs.pool_secret_path; + pool_conf = Unixext.string_of_file Xapi_globs.pool_config_file; + pool_token = Unixext.string_of_file Xapi_globs.pool_secret_path; schema_major_vsn = Datamodel.schema_major_vsn; schema_minor_vsn = Datamodel.schema_minor_vsn; product_version = Version.product_version; diff --git a/ocaml/database/generation.ml b/ocaml/database/generation.ml index 3fad3e77..105a8c84 100644 --- a/ocaml/database/generation.ml +++ b/ocaml/database/generation.ml @@ -79,4 +79,4 @@ let write_out_specified_count dbconn count = let read dbconn = let gencount_fname = gen_count_file dbconn in - try Int64.of_string (Unixext.read_whole_file_to_string gencount_fname) with _ -> 0L + try Int64.of_string (Unixext.string_of_file gencount_fname) with _ -> 0L diff --git a/ocaml/db_process/xapi-db-upgrade-4.2.ml b/ocaml/db_process/xapi-db-upgrade-4.2.ml index 17f7dd84..4dccbe1a 100644 --- a/ocaml/db_process/xapi-db-upgrade-4.2.ml +++ b/ocaml/db_process/xapi-db-upgrade-4.2.ml @@ -41,7 +41,7 @@ let (_:unit) = (fun dbconn -> let path = dbconn.Parse_db_conf.path in (* first, fit the database into memory *) - let state_db = Unixext.read_whole_file_to_string path in + let state_db = Unixext.string_of_file path in (* second, save the original database in a backup file, using a timestamp *) Unixext.write_string_to_file (path ^ ".prev_version." ^ (string_of_float (Unix.gettimeofday()))) state_db; (* finally, transform the database and replace the database file by a new one *) diff --git a/ocaml/gpg/gpg.ml b/ocaml/gpg/gpg.ml index 85628f7a..efa2cec6 100644 --- a/ocaml/gpg/gpg.ml +++ b/ocaml/gpg/gpg.ml @@ -102,7 +102,7 @@ let common ty filename signature size f = List.iter close' [ result_in; status_in ]; finally (* always waitpid eventually *) (fun () -> - let gpg_status = Unixext.read_whole_file 500 500 status_out in + let gpg_status = Unixext.string_of_fd status_out in let fingerprint = parse_gpg_status gpg_status in f fingerprint result_out) (fun () -> Forkhelpers.waitpid_fail_if_bad_exit pid)) with diff --git a/ocaml/license/license_file.ml b/ocaml/license/license_file.ml index 4eedd41e..66d0da29 100644 --- a/ocaml/license/license_file.ml +++ b/ocaml/license/license_file.ml @@ -61,7 +61,7 @@ let validate_signature fname = | None -> debug "No fingerprint!"; raise Gpg.InvalidSignature); - Unixext.read_whole_file 500 500 fd) + Unixext.string_of_fd fd) (* only activation keys are accepted as license files since XS 5.6 *) let parse_license license_data = diff --git a/ocaml/license/license_init.ml b/ocaml/license/license_init.ml index 361fbd89..2f034dac 100644 --- a/ocaml/license/license_init.ml +++ b/ocaml/license/license_init.ml @@ -23,7 +23,7 @@ let write_grace_to_file grace_expiry = let read_grace_from_file () = try - let grace_expiry_str = Unixext.read_whole_file_to_string Xapi_globs.upgrade_grace_file in + let grace_expiry_str = Unixext.string_of_file Xapi_globs.upgrade_grace_file in float_of_string grace_expiry_str with _ -> 0. diff --git a/ocaml/perftest/graphutil.ml b/ocaml/perftest/graphutil.ml index 6e50556e..7d56c4c5 100644 --- a/ocaml/perftest/graphutil.ml +++ b/ocaml/perftest/graphutil.ml @@ -50,7 +50,7 @@ let floats_from_file fname = let get_info ?(separate=false) files : info list = let aux f = - match Testtypes.from_string (Unixext.read_whole_file_to_string f) with + match Testtypes.from_string (Unixext.string_of_file f) with | None -> [ (f, "", ""), floats_from_file f] | Some results -> List.flatten (List.map (info_from_raw_result ~separate f) results) in diff --git a/ocaml/xapi/certificates.ml b/ocaml/xapi/certificates.ml index 2ba99660..b483c2b6 100644 --- a/ocaml/xapi/certificates.ml +++ b/ocaml/xapi/certificates.ml @@ -158,7 +158,7 @@ let get_cert is_cert name = raise_name_invalid is_cert name; let filename = library_filename is_cert name in try - read_whole_file_to_string filename + string_of_file filename with | e -> warn "Exception reading %s %s: %s" (get_type is_cert) name @@ -283,7 +283,7 @@ and trim_cert' acc = function let get_server_certificate () = try String.concat "\n" - (trim_cert (String.split '\n' (read_whole_file_to_string server_cert))) + (trim_cert (String.split '\n' (string_of_file server_cert))) with | e -> warn "Exception reading server certificate: %s" diff --git a/ocaml/xapi/config_file_io.ml b/ocaml/xapi/config_file_io.ml index eba074b9..330f1fe6 100644 --- a/ocaml/xapi/config_file_io.ml +++ b/ocaml/xapi/config_file_io.ml @@ -18,7 +18,7 @@ let _etc_passwd="/etc/passwd" let read_config_files() = - Unixext.read_whole_file_to_string _etc_passwd + Unixext.string_of_file _etc_passwd let rewrite_config_files s = Unixext.write_string_to_file _etc_passwd s (* a bit naughty, but will be fine.. ;) *) diff --git a/ocaml/xapi/config_file_sync.ml b/ocaml/xapi/config_file_sync.ml index aa607d14..5f0b0223 100644 --- a/ocaml/xapi/config_file_sync.ml +++ b/ocaml/xapi/config_file_sync.ml @@ -47,7 +47,7 @@ let fetch_config_files ~master_address ~pool_secret = (* no content length since it's streaming *) let _, _ = Xmlrpcclient.http_rpc_fd fd headers "" in let inchan = Unix.in_channel_of_descr fd in (* never read from fd again! *) - let config_files = Unixext.read_whole_file 1024 1024 fd in + let config_files = Unixext.string_of_fd fd in config_files ) (fun () -> Stunnel.disconnect st_proc) diff --git a/ocaml/xapi/dbsync_slave.ml b/ocaml/xapi/dbsync_slave.ml index 555044bc..aa32d39c 100644 --- a/ocaml/xapi/dbsync_slave.ml +++ b/ocaml/xapi/dbsync_slave.ml @@ -57,7 +57,7 @@ let get_start_time () = try debug "Calculating boot time..."; let now = Unix.time () in - let uptime = Unixext.read_whole_file_to_string "/proc/uptime" in + let uptime = Unixext.string_of_file "/proc/uptime" in let uptime = String.strip String.isspace uptime in let uptime = String.split ' ' uptime in let uptime = List.hd uptime in @@ -332,7 +332,7 @@ let record_host_memory_properties ~__context = let boot_memory_file = Xapi_globs.initial_host_free_memory_file in let boot_memory_string = try - Some (Unixext.read_whole_file_to_string boot_memory_file) + Some (Unixext.string_of_file boot_memory_file) with e -> warn "Could not read host free memory file. This may prevent \ VMs from being started on this host. (%s)" (Printexc.to_string e); diff --git a/ocaml/xapi/helpers.ml b/ocaml/xapi/helpers.ml index f38ff2a5..c4014fd1 100644 --- a/ocaml/xapi/helpers.ml +++ b/ocaml/xapi/helpers.ml @@ -468,7 +468,7 @@ let lookup_vdi_fields f vdi_refs l = (* Read pool secret if there, otherwise create a new one *) let get_pool_secret () = if (try (Unix.access pool_secret_path [Unix.F_OK]; true) with _ -> false) then - pool_secret := Unixext.read_whole_file_to_string pool_secret_path + pool_secret := Unixext.string_of_file pool_secret_path else begin let mk_rand_string () = Uuid.to_string (Uuid.make_uuid()) in @@ -703,7 +703,7 @@ let weighted_random_choice weighted_items (* list of (item, integer) weight *) = let loadavg () = let split_colon line = List.filter (fun x -> x <> "") (List.map (String.strip String.isspace) (String.split ' ' line)) in - let all = Unixext.read_whole_file_to_string "/proc/loadavg" in + let all = Unixext.string_of_file "/proc/loadavg" in try float_of_string (List.hd (split_colon all)) with _ -> -1. diff --git a/ocaml/xapi/monitor_rrds.ml b/ocaml/xapi/monitor_rrds.ml index b2c885e8..e5865f70 100644 --- a/ocaml/xapi/monitor_rrds.ml +++ b/ocaml/xapi/monitor_rrds.ml @@ -101,11 +101,11 @@ let read_gzipped_file_with_fallback path = if gz_exists then begin Unixext.with_file gz_path [ Unix.O_RDONLY ] 0o0 (fun fd -> Gzip.decompress_passive fd - (fun fd -> result := Unixext.read_whole_file 1024 1024 fd)); + (fun fd -> result := Unixext.string_of_fd fd)); !result end else begin (* If this fails, let the exception propagate *) - Unixext.read_whole_file_to_string path + Unixext.string_of_file path end diff --git a/ocaml/xapi/monitor_self.ml b/ocaml/xapi/monitor_self.ml index 2664af4b..3687fb5d 100644 --- a/ocaml/xapi/monitor_self.ml +++ b/ocaml/xapi/monitor_self.ml @@ -48,7 +48,7 @@ let split_colon line = List.filter (fun x -> x <> "") (List.map (String.strip String.isspace) (String.split ' ' line)) let meminfo () = - let all = Unixext.read_whole_file_to_string "/proc/meminfo" in + let all = Unixext.string_of_file "/proc/meminfo" in let total = ref (-1) and free = ref (-1) and buffered = ref (-1) @@ -71,7 +71,7 @@ let string_of_meminfo (x: meminfo) = Printf.sprintf "MemTotal: %d KiB; MemFree: %d KiB; Buffered: %d KiB; Cached: %d KiB; SwapTotal: %d KiB; SwapFree: %d KiB" x.total x.free x.buffered x.cached x.swap_total x.swap_free let process_memory_info_of_pid (pid: int) = - let all = Unixext.read_whole_file_to_string (Printf.sprintf "/proc/%d/status" pid) in + let all = Unixext.string_of_file (Printf.sprintf "/proc/%d/status" pid) in let peak = ref (-1) and size = ref (-1) and locked = ref (-1) diff --git a/ocaml/xapi/parse_db_conf.ml b/ocaml/xapi/parse_db_conf.ml index 2e3e5713..763150d8 100644 --- a/ocaml/xapi/parse_db_conf.ml +++ b/ocaml/xapi/parse_db_conf.ml @@ -89,7 +89,7 @@ let sanity_check connections = let parse_db_conf s = try - let conf = Unixext.read_whole_file_to_string s in + let conf = Unixext.string_of_file s in let lines : string list ref = ref [] in let consume_line() = lines := List.tl !lines in lines := String.split '\n' conf; diff --git a/ocaml/xapi/pool_role.ml b/ocaml/xapi/pool_role.ml index 1f1bd128..e65259da 100644 --- a/ocaml/xapi/pool_role.ml +++ b/ocaml/xapi/pool_role.ml @@ -33,7 +33,7 @@ let string_of_t = function | Broken -> "broken" let read_pool_role() = - let s = String.strip String.isspace (Unixext.read_whole_file_to_string Xapi_globs.pool_config_file) in + let s = String.strip String.isspace (Unixext.string_of_file Xapi_globs.pool_config_file) in match String.split ~limit:2 ':' s with | [ "master" ] -> Master | [ "slave"; m_ip ] -> Slave m_ip diff --git a/ocaml/xapi/quicktest.ml b/ocaml/xapi/quicktest.ml index d6222e09..30a1244a 100644 --- a/ocaml/xapi/quicktest.ml +++ b/ocaml/xapi/quicktest.ml @@ -334,7 +334,7 @@ let vbd_pause_unpause_test session_id vm = vm_uninstall test session_id vm); success test -let read_sys path = Stringext.String.strip Stringext.String.isspace (Unixext.read_whole_file_to_string path) +let read_sys path = Stringext.String.strip Stringext.String.isspace (Unixext.string_of_file path) let verify_network_connectivity session_id test vm = let vifs = Client.VM.get_VIFs !rpc session_id vm in diff --git a/ocaml/xapi/remote_requests.ml b/ocaml/xapi/remote_requests.ml index 9447ed7a..6c859229 100644 --- a/ocaml/xapi/remote_requests.ml +++ b/ocaml/xapi/remote_requests.ml @@ -193,7 +193,7 @@ let stop_request_thread () = let read_response result content_length task_id s = try - result := Unixext.read_whole_file 1024 1024 s + result := Unixext.string_of_fd s with | Unix.Unix_error(Unix.ECONNRESET, _, _) -> raise Xmlrpcclient.Connection_reset diff --git a/ocaml/xapi/rrddump.ml b/ocaml/xapi/rrddump.ml index 37ed88f5..a02eee75 100644 --- a/ocaml/xapi/rrddump.ml +++ b/ocaml/xapi/rrddump.ml @@ -16,7 +16,7 @@ *) let _ = - let body = Unixext.read_whole_file_to_string Sys.argv.(1) in + let body = Unixext.string_of_file Sys.argv.(1) in let input = Xmlm.make_input (`String (0, body)) in let rrd = Rrd.from_xml input in Rrd.text_export rrd [] diff --git a/ocaml/xapi/static_vdis_list.ml b/ocaml/xapi/static_vdis_list.ml index c92c7ae0..3bddaf59 100644 --- a/ocaml/xapi/static_vdis_list.ml +++ b/ocaml/xapi/static_vdis_list.ml @@ -31,8 +31,8 @@ let list () = let all = try Array.to_list (Sys.readdir main_dir) with Sys_error _ -> [] in List.map (fun x -> let path = Filename.concat main_dir x in - let uuid = Unixext.read_whole_file_to_string (Filename.concat path "vdi-uuid") in - let reason = Unixext.read_whole_file_to_string (Filename.concat path "reason") in + let uuid = Unixext.string_of_file (Filename.concat path "vdi-uuid") in + let reason = Unixext.string_of_file (Filename.concat path "reason") in let bool_of_string x = String.lowercase x = "true" in let delete_next_boot = try ignore(Unix.stat (Filename.concat path "delete-next-boot")); true diff --git a/ocaml/xapi/xapi.ml b/ocaml/xapi/xapi.ml index 484f3382..0f6ff995 100644 --- a/ocaml/xapi/xapi.ml +++ b/ocaml/xapi/xapi.ml @@ -541,7 +541,7 @@ let record_boot_time_host_free_memory () = let check_network_reset () = try (* Raises exception if the file is not there and no reset is required *) - let reset_file = Unixext.read_whole_file_to_string (Xapi_globs.network_reset_trigger) in + let reset_file = Unixext.string_of_file (Xapi_globs.network_reset_trigger) in Server_helpers.exec_with_new_task "Performing emergency network reset" (fun __context -> let host = Helpers.get_localhost ~__context in diff --git a/ocaml/xapi/xapi_fist.ml b/ocaml/xapi/xapi_fist.ml index e5b29acc..31742a42 100644 --- a/ocaml/xapi/xapi_fist.ml +++ b/ocaml/xapi/xapi_fist.ml @@ -24,7 +24,7 @@ let fistpoint name = try Unix.access ("/tmp/fist_" ^ name) [ Unix.F_OK ]; true w let fistpoint_read name = try - Some (Unixext.read_whole_file_to_string ("/tmp/fist_" ^ name)) + Some (Unixext.string_of_file ("/tmp/fist_" ^ name)) with _ -> None let delete name = Unixext.unlink_safe ("/tmp/fist_" ^ name) diff --git a/ocaml/xapi/xapi_pool_patch.ml b/ocaml/xapi/xapi_pool_patch.ml index 60f9a10c..4dba0d7a 100644 --- a/ocaml/xapi/xapi_pool_patch.ml +++ b/ocaml/xapi/xapi_pool_patch.ml @@ -539,7 +539,7 @@ let update_db ~__context = (* Full paths of the /var/patch/applied files *) let stampfiles = List.map (Filename.concat patch_applied_dir) (try Array.to_list (Sys.readdir patch_applied_dir) with _ -> []) in let parse x = - try [ patch_info_of_string (Unixext.read_whole_file_to_string x), (Unix.stat x).Unix.st_mtime ] + try [ patch_info_of_string (Unixext.string_of_file x), (Unix.stat x).Unix.st_mtime ] with e -> warn "Error parsing patch stampfile %s: %s" x (ExnHelper.string_of_exn e); [] in List.concat (List.map parse stampfiles) in diff --git a/ocaml/xe-cli/newcli.ml b/ocaml/xe-cli/newcli.ml index b8419ef9..f162b6a5 100644 --- a/ocaml/xe-cli/newcli.ml +++ b/ocaml/xe-cli/newcli.ml @@ -536,7 +536,7 @@ let main () = close_out ch; if !exit_status <> 0 then begin output_string stderr "\nDebug info:\n\n"; - output_string stderr (Unixext.read_whole_file_to_string f) + output_string stderr (Unixext.string_of_file f) end; try Unix.unlink f with _ -> () end diff --git a/ocaml/xenops/device.ml b/ocaml/xenops/device.ml index 92b476cf..1a2d1ee0 100644 --- a/ocaml/xenops/device.ml +++ b/ocaml/xenops/device.ml @@ -1357,7 +1357,7 @@ let write_logfile_to_log domid = try let fd = Unix.openfile logfile [ Unix.O_RDONLY ] 0o0 in finally - (fun () -> debug "qemu-dm: logfile contents: %s" (Unixext.read_whole_file 1024 1024 fd)) + (fun () -> debug "qemu-dm: logfile contents: %s" (Unixext.string_of_fd fd)) (fun () -> Unix.close fd) with e -> debug "Caught exception reading qemu log file from %s: %s" logfile (Printexc.to_string e); @@ -1589,7 +1589,7 @@ let stop ~xs domid = in let readcmdline pid = try - match Unixext.read_whole_file_to_string (sprintf "/proc/%d/cmdline" pid) with + match Unixext.string_of_file (sprintf "/proc/%d/cmdline" pid) with | "" -> None (* CA-27800: proc/cmdline returns empty strings during _exit() *) | x -> Some x with e -> None in