diff --git a/src/proc.cpp b/src/proc.cpp index f415df14d..00b1db12d 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -562,58 +562,60 @@ int job_reap(bool allow_interactive) { proc_fire_event(L"PROCESS_EXIT", EVENT_EXIT, p->pid, (WIFSIGNALED(s) ? -1 : WEXITSTATUS(s))); - // Ignore signal SIGPIPE.We issue it ourselves to the pipe writer when the pipe - // reader dies. - if (WIFSIGNALED(s) && WTERMSIG(s) != SIGPIPE) { - int proc_is_job = ((p == j->first_process) && (p->next == 0)); - if (proc_is_job) job_set_flag(j, JOB_NOTIFIED, 1); - if (!job_get_flag(j, JOB_SKIP_NOTIFICATION)) { - // Print nothing if we get SIGINT in the foreground process group, to avoid - // spamming obvious stuff on the console (#1119). If we get SIGINT for the - // foreground process, assume the user typed ^C and can see it working. It's - // possible they didn't, and the signal was delivered via pkill, etc., but - // the SIGINT/SIGTERM distinction is precisely to allow INT to be from a UI - // and TERM to be programmatic, so this assumption is keeping with the - // design of signals. If echoctl is on, then the terminal will have written - // ^C to the console. If off, it won't have. We don't echo ^C either way, so - // as to respect the user's preference. - if (WTERMSIG(p->status) != SIGINT || !job_get_flag(j, JOB_FOREGROUND)) { - if (proc_is_job) { - // We want to report the job number, unless it's the only job, in - // which case we don't need to. - const wcstring job_number_desc = - (job_count == 1) ? wcstring() - : format_string(L"Job %d, ", j->job_id); - fwprintf(stdout, _(L"%ls: %ls\'%ls\' terminated by signal %ls (%ls)"), - program_name, job_number_desc.c_str(), - truncate_command(j->command()).c_str(), - sig2wcs(WTERMSIG(p->status)), - signal_get_desc(WTERMSIG(p->status))); - } else { - const wcstring job_number_desc = - (job_count == 1) ? wcstring() - : format_string(L"from job %d, ", j->job_id); - fwprintf(stdout, _(L"%ls: Process %d, \'%ls\' %ls\'%ls\' " - L"terminated by signal %ls (%ls)"), - program_name, p->pid, p->argv0(), job_number_desc.c_str(), - truncate_command(j->command()).c_str(), - sig2wcs(WTERMSIG(p->status)), - signal_get_desc(WTERMSIG(p->status))); - } + // Ignore signal SIGPIPE.We issue it ourselves to the pipe writer when the pipe reader + // dies. + if (!WIFSIGNALED(s) || WTERMSIG(s) == SIGPIPE) { + continue; + } - if (cur_term != NULL) - tputs(clr_eol, 1, &writeb); - else - fwprintf(stdout, L"\x1b[K"); // no term set up - do clr_eol manually + // Handle signals other than SIGPIPE. + int proc_is_job = ((p == j->first_process) && (p->next == 0)); + if (proc_is_job) job_set_flag(j, JOB_NOTIFIED, 1); + if (job_get_flag(j, JOB_SKIP_NOTIFICATION)) { + continue; + } - fwprintf(stdout, L"\n"); - } - found = 1; + // Print nothing if we get SIGINT in the foreground process group, to avoid spamming + // obvious stuff on the console (#1119). If we get SIGINT for the foreground + // process, assume the user typed ^C and can see it working. It's possible they + // didn't, and the signal was delivered via pkill, etc., but the SIGINT/SIGTERM + // distinction is precisely to allow INT to be from a UI + // and TERM to be programmatic, so this assumption is keeping with the design of + // signals. If echoctl is on, then the terminal will have written ^C to the console. + // If off, it won't have. We don't echo ^C either way, so as to respect the user's + // preference. + if (WTERMSIG(p->status) != SIGINT || !job_get_flag(j, JOB_FOREGROUND)) { + if (proc_is_job) { + // We want to report the job number, unless it's the only job, in which case + // we don't need to. + const wcstring job_number_desc = + (job_count == 1) ? wcstring() : format_string(L"Job %d, ", j->job_id); + fwprintf(stdout, _(L"%ls: %ls\'%ls\' terminated by signal %ls (%ls)"), + program_name, job_number_desc.c_str(), + truncate_command(j->command()).c_str(), + sig2wcs(WTERMSIG(p->status)), + signal_get_desc(WTERMSIG(p->status))); + } else { + const wcstring job_number_desc = + (job_count == 1) ? wcstring() + : format_string(L"from job %d, ", j->job_id); + fwprintf(stdout, _(L"%ls: Process %d, \'%ls\' %ls\'%ls\' " + L"terminated by signal %ls (%ls)"), + program_name, p->pid, p->argv0(), job_number_desc.c_str(), + truncate_command(j->command()).c_str(), + sig2wcs(WTERMSIG(p->status)), + signal_get_desc(WTERMSIG(p->status))); } - // Clear status so it is not reported more than once. - p->status = 0; + if (cur_term != NULL) { + tputs(clr_eol, 1, &writeb); + } else { + fwprintf(stdout, L"\x1b[K"); // no term set up - do clr_eol manually + } + fwprintf(stdout, L"\n"); } + found = 1; + p->status = 0; // clear status so it is not reported more than once } // If all processes have completed, tell the user the job has completed and delete it from