summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-10-26 02:35:22 +0330
committerAndreas Kling <kling@serenityos.org>2020-10-26 14:28:38 +0100
commit6d7b01a3cf01fac2fccb5a9821e145257954a2ab (patch)
tree44b4b4c5326b6b91136266a06968313a8e15d24e
parent5a4673d46855a0fa85381fecd8bd4f49735c1d18 (diff)
downloadserenity-6d7b01a3cf01fac2fccb5a9821e145257954a2ab.zip
Shell: Use kill() in fg/bg if killpg() fails
A job might not have its own pgid if it's created through run_tail().
-rw-r--r--Shell/Builtin.cpp22
1 files 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);