Shell: Use kill_job() to kill jobs

This commit is contained in:
AnotherTest 2020-10-28 17:21:40 +03:30 committed by Andreas Kling
parent 384e872ff9
commit c92865bd05

View file

@ -1580,11 +1580,12 @@ Shell::~Shell()
void Shell::stop_all_jobs() void Shell::stop_all_jobs()
{ {
if (!jobs.is_empty()) { 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) { for (auto& entry : jobs) {
if (!entry.value->is_running_in_background()) { if (entry.value->is_suspended()) {
#ifdef SH_DEBUG #ifdef SH_DEBUG
dbg() << "Job " << entry.value->pid() << " is not running in background"; dbg() << "Job " << entry.value->pid() << " is suspended";
#endif #endif
kill_job(entry.value, SIGCONT); kill_job(entry.value, SIGCONT);
} }
@ -1598,11 +1599,7 @@ void Shell::stop_all_jobs()
#ifdef SH_DEBUG #ifdef SH_DEBUG
dbg() << "Actively killing " << entry.value->pid() << "(" << entry.value->cmd() << ")"; dbg() << "Actively killing " << entry.value->pid() << "(" << entry.value->cmd() << ")";
#endif #endif
if (killpg(entry.value->pgid(), SIGKILL) < 0) { kill_job(entry.value, SIGKILL);
if (errno == ESRCH)
continue; // The process has exited all by itself.
perror("killpg(KILL)");
}
} }
jobs.clear(); jobs.clear();
@ -1633,8 +1630,11 @@ void Shell::kill_job(const Job* job, int sig)
if (!job) if (!job)
return; return;
if (killpg(job->pgid(), sig) < 0) if (killpg(job->pgid(), sig) < 0) {
perror("killpg(job)"); if (kill(job->pid(), sig) < 0) {
perror("kill");
}
}
} }
void Shell::save_to(JsonObject& object) void Shell::save_to(JsonObject& object)