mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:27:35 +00:00
Shell: Use kill() in fg/bg if killpg() fails
A job might not have its own pgid if it's created through run_tail().
This commit is contained in:
parent
5a4673d468
commit
6d7b01a3cf
1 changed files with 14 additions and 8 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue