]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
CA-44731: replace uses of read_whole_file_to_string with string_of_file
authorDavid Scott <dave.scott@eu.citrix.com>
Tue, 12 Oct 2010 09:33:26 +0000 (10:33 +0100)
committerDavid Scott <dave.scott@eu.citrix.com>
Tue, 12 Oct 2010 09:33:26 +0000 (10:33 +0100)
Signed-off-by: David Scott <dave.scott@eu.citrix.com>
25 files changed:
ocaml/database/db_cache_types.ml
ocaml/database/generation.ml
ocaml/db_process/xapi-db-upgrade-4.2.ml
ocaml/gpg/gpg.ml
ocaml/license/license_file.ml
ocaml/license/license_init.ml
ocaml/perftest/graphutil.ml
ocaml/xapi/certificates.ml
ocaml/xapi/config_file_io.ml
ocaml/xapi/config_file_sync.ml
ocaml/xapi/dbsync_slave.ml
ocaml/xapi/helpers.ml
ocaml/xapi/monitor_rrds.ml
ocaml/xapi/monitor_self.ml
ocaml/xapi/parse_db_conf.ml
ocaml/xapi/pool_role.ml
ocaml/xapi/quicktest.ml
ocaml/xapi/remote_requests.ml
ocaml/xapi/rrddump.ml
ocaml/xapi/static_vdis_list.ml
ocaml/xapi/xapi.ml
ocaml/xapi/xapi_fist.ml
ocaml/xapi/xapi_pool_patch.ml
ocaml/xe-cli/newcli.ml
ocaml/xenops/device.ml

index f150d0909cadfc4c41abeda8d26e7be9eb8c1a97..d22fc2b09f95f2b9b87fe6d1ccf6de6c787d4478 100644 (file)
@@ -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;
index 3fad3e770fab5daa74ba80343a79c55dc6549e34..105a8c84b83fd7a14b6d82a5408b00ddcaba2f50 100644 (file)
@@ -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
index 17f7dd847f828985e75752579e101e58a3dd68e4..4dccbe1a322225928d615a8849447105a8208d88 100644 (file)
@@ -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 *)
index 85628f7a8563a20604a4c6a95cdcd4b5e3f19311..efa2cec612a9889d38daf7d63164f7cf0f63b2f0 100644 (file)
@@ -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
index 4eedd41e49a93b16192cccaf134d6cdf74630e8d..66d0da295371ef047bdec89a511022042037889d 100644 (file)
@@ -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 =
index 361fbd89423a33ba6920679b9de0308225bb9482..2f034dacad2abdb023e5d3444d86c7951c6174bb 100644 (file)
@@ -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.
 
index 6e50556e0ceb6414f17105598d7381127bee7657..7d56c4c5be9f73e0dae75d51629c15116ac91b8a 100644 (file)
@@ -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
index 2ba99660e2dd6a7c5af372f642330dd527735f5b..b483c2b629976d62e0c070f25cf1d54e1cdac068 100644 (file)
@@ -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"
index eba074b983aa905ca51f28d3e655d6a033e3e097..330f1fe6cd7822a58bac3da8354c758d9f7b7b9b 100644 (file)
@@ -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.. ;) *)
 
index aa607d14e7a0d276fb0167233ce793f1970fb232..5f0b0223d0b87084e50f2330f8e1cb9f712334fa 100644 (file)
@@ -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)
index 555044bc933c82392559e920e7390d74be57eb45..aa32d39c8b83a7ddb1bbd2b99249b8f81dbd4de5 100644 (file)
@@ -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);
index f38ff2a5e5e65e249b9c4bee618f6e305dfc08ff..c4014fd1949835b77a442c01b3dddc759245318f 100644 (file)
@@ -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.
index b2c885e8d9dbff9344227c0c46446c5d60954067..e5865f700404e1491be92be6989f2f4d2cb8e1cf 100644 (file)
@@ -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
 
 
index 2664af4bafc57d90046cf67010d5e28facf4f13f..3687fb5d0a24059e0ec8ab29a9ea02e306f17e3f 100644 (file)
@@ -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)
index 2e3e571342ae7029b22b931e25cf164da6072cae..763150d8172ad10853c4a6bb9399fef073a0896e 100644 (file)
@@ -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;
index 1f1bd128e4f28a60621bc29dfbee6ff597f10210..e65259da774c2a0b5893404bf6bd7c6772445d04 100644 (file)
@@ -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
index d6222e09860ba699961eb90b81727582f5dfdcc6..30a1244a504516794335c33f180e9f595510b0d2 100644 (file)
@@ -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
index 9447ed7a1fe6aa437b3f1e9562740964dbe1d5fa..6c859229e2e0ac6ea9c30c98aed424c3b4fb2f6d 100644 (file)
@@ -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
index 37ed88f5c0ff36d8f08af1289b6eb0884dd23280..a02eee757e173f28889e451a9615123728323396 100644 (file)
@@ -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 []
index c92c7ae01df62fa234765286aa720787595dc334..3bddaf59ff85bf324764a6d043e7246a00a80656 100644 (file)
@@ -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 
index 484f3382e0b57064d737149d55081848b3231ba9..0f6ff995bb33c685ac674a032b9b68b6398e3d79 100644 (file)
@@ -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
index e5b29acc06d1c8db686c366f012ae0b427aef699..31742a424fc3dbeda130bd724b5747ccba03275f 100644 (file)
@@ -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)
index 60f9a10caf486eb236269afcbd6593fa1aba1ce8..4dba0d7a9a605401a7499f58db70430224e44aa6 100644 (file)
@@ -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
 
index b8419ef93b6bacc9139e5db59a522a3214afd479..f162b6a57c23e11387bcaf4aa4c91becd3f2e04c 100644 (file)
@@ -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
index 92b476cf8a9a85a6740aed301cc41f1ca7479ddc..1a2d1ee00d64169c9a615103e312fa7a53b94669 100644 (file)
@@ -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