From 4610ec860020b84f0966a326b40a0c964c385932 Mon Sep 17 00:00:00 2001 From: Marcus Granado Date: Tue, 12 Oct 2010 12:15:20 +0100 Subject: [PATCH] CA-46210: use nice to work around forkhelpers waitpid race Signed-off-by: Marcus Granado --- stdext/gzip.ml | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/stdext/gzip.ml b/stdext/gzip.ml index 1c01731..805ae02 100644 --- a/stdext/gzip.ml +++ b/stdext/gzip.ml @@ -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 () -> -- 2.39.5