Refactor linux kill_child code
@@ -115,16 +115,22 @@ pub fn kill_child(task_id: usize, child: &mut Child, kill_children: bool) -> boo
}
// Kill the parent first
- match child.kill() {
- Err(_) => {
+ let kill_result = child.kill();
+ if kill_result.is_err() {
info!("Task {} has already finished by itself", task_id);
- false
+ return false;
}
- _ => {
- // Now kill all remaining children, after the parent has been killed.
+
+ // Do an early return, if we don't need to kill any children.
+ let child_processes = if let Some(child_processes) = child_processes {
+ child_processes
+ } else {
+ return true;
+ };
+
+ // Now kill all remaining children. The parent has been already been killed at this point.
// If a shell is spawned, we have to manually send the kill signal to all children.
// Otherwise only send a signal to all children if the `kill_children` flag is set.
- if let Some(child_processes) = child_processes {
if is_shell {
for child_process in child_processes {
// Send the signal to each child process, show warning if this fails.
@@ -141,12 +147,9 @@ pub fn kill_child(task_id: usize, child: &mut Child, kill_children: bool) -> boo
} else if kill_children {
send_signal_to_processes(child_processes, &ProcessAction::Kill);
}
- }
true
}
- }
-}
/// Check whether a process's commandline string is actually a shell or not
fn did_process_spawn_shell(pid: i32) -> Result<bool> {
