From 6d7b01a3cf01fac2fccb5a9821e145257954a2ab Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Mon, 26 Oct 2020 02:35:22 +0330 Subject: [PATCH] Shell: Use kill() in fg/bg if killpg() fails A job might not have its own pgid if it's created through run_tail(). --- Shell/Builtin.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Shell/Builtin.cpp b/Shell/Builtin.cpp index c719abef32..73550e2d4a 100644 --- a/Shell/Builtin.cpp +++ b/Shell/Builtin.cpp @@ -99,12 +99,15 @@ int Shell::builtin_bg(int argc, const char** argv) job->set_running_in_background(true); job->set_is_suspended(false); - dbg() << "Resuming " << job->pid() << " (" << job->cmd() << ")"; - fprintf(stderr, "Resuming job %" PRIu64 " - %s\n", job->job_id(), job->cmd().characters()); + dbgln("Resuming {} ({})", job->pid(), job->cmd()); + warnln("Resuming job {} - {}", job->job_id(), job->cmd().characters()); + // Try using the PGID, but if that fails, just use the PID. if (killpg(job->pgid(), SIGCONT) < 0) { - perror("killpg"); - return 1; + if (kill(job->pid(), SIGCONT) < 0) { + perror("kill"); + return 1; + } } return 0; @@ -347,15 +350,18 @@ int Shell::builtin_fg(int argc, const char** argv) job->set_running_in_background(false); job->set_is_suspended(false); - dbg() << "Resuming " << job->pid() << " (" << job->cmd() << ")"; - fprintf(stderr, "Resuming job %" PRIu64 " - %s\n", job->job_id(), job->cmd().characters()); + dbgln("Resuming {} ({})", job->pid(), job->cmd()); + warnln("Resuming job {} - {}", job->job_id(), job->cmd().characters()); tcsetpgrp(STDOUT_FILENO, job->pgid()); tcsetpgrp(STDIN_FILENO, job->pgid()); + // Try using the PGID, but if that fails, just use the PID. if (killpg(job->pgid(), SIGCONT) < 0) { - perror("killpg"); - return 1; + if (kill(job->pid(), SIGCONT) < 0) { + perror("kill"); + return 1; + } } block_on_job(job);