]> xenbits.xensource.com Git - xcp/xen-api-libs.git/commitdiff
CA-46210: use nice to work around forkhelpers waitpid race
authorMarcus Granado <marcus.granado@eu.citrix.com>
Tue, 12 Oct 2010 11:15:20 +0000 (12:15 +0100)
committerMarcus Granado <marcus.granado@eu.citrix.com>
Tue, 12 Oct 2010 11:15:20 +0000 (12:15 +0100)
Signed-off-by: Marcus Granado <marcus.granado@eu.citrix.com>
stdext/gzip.ml

index 1c017317e4e257e10bf408a40f6e8620d45cf961..805ae02ef415b677c29b6598a8156198609c5cb2 100644 (file)
@@ -28,19 +28,18 @@ type input_type =
   | Active  (** we provide a function which writes into the compressor and a fd output *)
   | Passive (** we provide an fd input and a function which reads from the compressor *)
 
-(* renice/ionice the pid with lowest priority so that it doesn't *)
-(* use up all cpu resources in dom0 *)
-let lower_priority pid =
-  let pid=Printf.sprintf "%d" (Forkhelpers.getpid pid) in
-  (* renice 19 -p pid *)
-  let renice="/usr/bin/renice" in
-  let renice_args = ["19";"-p";pid] in
-  let _=Forkhelpers.execute_command_get_output renice renice_args in
-  (* ionice -c 3 [idle] -p pid *)
+(* start cmd with lowest priority so that it doesn't 
+   use up all cpu resources in dom0 
+*)
+let lower_priority cmd args =
   let ionice="/usr/bin/ionice" in
-  let ionice_args = ["-c";"3";"-p";pid] in
-  let _=Forkhelpers.execute_command_get_output ionice ionice_args in
-  ()
+  let ionice_args=["-c";"3"] in (*io idle*)
+  let nice="/bin/nice" in
+  let nice_args=["-n";"19"] in (*lowest priority*)
+  let extra_args=nice_args@[ionice]@ionice_args in
+  let new_cmd=nice in
+  let new_args=extra_args@[cmd]@args in
+  (new_cmd,new_args)
 
 (** Runs a zcat process which is either:
     i) a compressor; or (ii) a decompressor
@@ -69,11 +68,11 @@ let go (mode: zcat_mode) (input: input_type) fd f =
               Some zcat_in,                               (* output goes into the pipe+fn *) 
               zcat_in,                                    (* we close this now *)
               zcat_out in                                 (* close this before waitpid *)
+        let (gzip,args)=lower_priority gzip args in
         let pid = Forkhelpers.safe_close_and_exec stdin stdout None [] gzip args in
         close close_now;
    finally
      (fun () -> 
-       (try lower_priority pid with _->()); (* lowest priority to gzip *)
        f close_later
      )
           (fun () ->