diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-07-12 18:51:47 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-13 15:29:16 +0200 |
commit | 151e4d41ed30a49d7652d2d5a331eb14f9db86f0 (patch) | |
tree | dabb3fdc3b1044a4bc732fbefef7e0149f59b5c6 /Shell/Builtin.cpp | |
parent | 3a7a689b87d85948b10b769ea5b562c90c6be63a (diff) | |
download | serenity-151e4d41ed30a49d7652d2d5a331eb14f9db86f0.zip |
Shell: Put children in their own process groups and fix job control
This commit fixes job control by putting children in their own process
group, and proxying TTY signals to active jobs.
This also cleans up the code around builtin_disown a bit to use
the newer job interfaces.
Diffstat (limited to 'Shell/Builtin.cpp')
-rw-r--r-- | Shell/Builtin.cpp | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/Shell/Builtin.cpp b/Shell/Builtin.cpp index a2e77c4183..1eace438f0 100644 --- a/Shell/Builtin.cpp +++ b/Shell/Builtin.cpp @@ -372,44 +372,33 @@ int Shell::builtin_disown(int argc, const char** argv) fprintf(stderr, "disown: Invalid job id %s\n", job_id); } - if (job_ids.is_empty()) { - u64 id = 0; - for (auto& job : jobs) - id = max(id, job.value->job_id()); - job_ids.append(id); - } + if (job_ids.is_empty()) + job_ids.append(find_last_job_id()); - Vector<size_t> keys_of_jobs_to_disown; + Vector<const Job*> jobs_to_disown; for (auto id : job_ids) { - bool found = false; - for (auto& entry : jobs) { - if (entry.value->job_id() == id) { - keys_of_jobs_to_disown.append(entry.key); - found = true; - break; - } - } - if (!found) { + auto job = find_job(id); + if (!job) fprintf(stderr, "disown: job with id %zu not found\n", id); - } + else + jobs_to_disown.append(job); } - if (keys_of_jobs_to_disown.is_empty()) { - if (str_job_ids.is_empty()) { + + if (jobs_to_disown.is_empty()) { + if (str_job_ids.is_empty()) fprintf(stderr, "disown: no current job\n"); - } // An error message has already been printed about the nonexistence of each listed job. return 1; } - for (auto job_index : keys_of_jobs_to_disown) { - auto job = jobs.get(job_index).value(); + for (auto job : jobs_to_disown) { job->deactivate(); if (!job->is_running_in_background()) fprintf(stderr, "disown warning: job %" PRIu64 " is currently not running, 'kill -%d %d' to make it continue\n", job->job_id(), SIGCONT, job->pid()); - jobs.remove(job_index); + jobs.remove(job->pid()); } return 0; |