job_get_from_pid: don't assume pgid == pid

Compare apples with apples by using getpgid() when checking a process
against the job list.
This commit is contained in:
David Adam 2017-04-23 22:04:37 +08:00
parent d32e7f5ad7
commit 10e64fd548

View File

@ -569,8 +569,21 @@ job_t *parser_t::job_get(job_id_t id) {
job_t *parser_t::job_get_from_pid(pid_t pid) {
job_iterator_t jobs;
job_t *job;
pid_t pgid = getpgid(pid);
if (pgid == -1) {
return 0;
}
while ((job = jobs.next())) {
if (job->pgid == pid) return job;
if (job->pgid == pgid) {
for (const process_ptr_t &p : job->processes) {
if (p->pid == pid) {
return job;
}
}
}
}
return 0;
}