From c92865bd0590b6e5aade00766ea81d50840030b6 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Wed, 28 Oct 2020 17:21:40 +0330 Subject: [PATCH] Shell: Use kill_job() to kill jobs --- Shell/Shell.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Shell/Shell.cpp b/Shell/Shell.cpp index 8c787f3b84..5313ac52c4 100644 --- a/Shell/Shell.cpp +++ b/Shell/Shell.cpp @@ -1580,11 +1580,12 @@ Shell::~Shell() void Shell::stop_all_jobs() { if (!jobs.is_empty()) { - printf("Killing active jobs\n"); + if (m_is_interactive && !m_is_subshell) + printf("Killing active jobs\n"); for (auto& entry : jobs) { - if (!entry.value->is_running_in_background()) { + if (entry.value->is_suspended()) { #ifdef SH_DEBUG - dbg() << "Job " << entry.value->pid() << " is not running in background"; + dbg() << "Job " << entry.value->pid() << " is suspended"; #endif kill_job(entry.value, SIGCONT); } @@ -1598,11 +1599,7 @@ void Shell::stop_all_jobs() #ifdef SH_DEBUG dbg() << "Actively killing " << entry.value->pid() << "(" << entry.value->cmd() << ")"; #endif - if (killpg(entry.value->pgid(), SIGKILL) < 0) { - if (errno == ESRCH) - continue; // The process has exited all by itself. - perror("killpg(KILL)"); - } + kill_job(entry.value, SIGKILL); } jobs.clear(); @@ -1633,8 +1630,11 @@ void Shell::kill_job(const Job* job, int sig) if (!job) return; - if (killpg(job->pgid(), sig) < 0) - perror("killpg(job)"); + if (killpg(job->pgid(), sig) < 0) { + if (kill(job->pid(), sig) < 0) { + perror("kill"); + } + } } void Shell::save_to(JsonObject& object)