mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
lint: Use early exit/continue
This commit is contained in:
parent
7779132595
commit
4fe2a2921f
1 changed files with 49 additions and 47 deletions
96
src/proc.cpp
96
src/proc.cpp
|
@ -562,58 +562,60 @@ int job_reap(bool allow_interactive) {
|
||||||
proc_fire_event(L"PROCESS_EXIT", EVENT_EXIT, p->pid,
|
proc_fire_event(L"PROCESS_EXIT", EVENT_EXIT, p->pid,
|
||||||
(WIFSIGNALED(s) ? -1 : WEXITSTATUS(s)));
|
(WIFSIGNALED(s) ? -1 : WEXITSTATUS(s)));
|
||||||
|
|
||||||
// Ignore signal SIGPIPE.We issue it ourselves to the pipe writer when the pipe
|
// Ignore signal SIGPIPE.We issue it ourselves to the pipe writer when the pipe reader
|
||||||
// reader dies.
|
// dies.
|
||||||
if (WIFSIGNALED(s) && WTERMSIG(s) != SIGPIPE) {
|
if (!WIFSIGNALED(s) || WTERMSIG(s) == SIGPIPE) {
|
||||||
int proc_is_job = ((p == j->first_process) && (p->next == 0));
|
continue;
|
||||||
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)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cur_term != NULL)
|
// Handle signals other than SIGPIPE.
|
||||||
tputs(clr_eol, 1, &writeb);
|
int proc_is_job = ((p == j->first_process) && (p->next == 0));
|
||||||
else
|
if (proc_is_job) job_set_flag(j, JOB_NOTIFIED, 1);
|
||||||
fwprintf(stdout, L"\x1b[K"); // no term set up - do clr_eol manually
|
if (job_get_flag(j, JOB_SKIP_NOTIFICATION)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
fwprintf(stdout, L"\n");
|
// 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
|
||||||
found = 1;
|
// 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.
|
if (cur_term != NULL) {
|
||||||
p->status = 0;
|
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
|
// If all processes have completed, tell the user the job has completed and delete it from
|
||||||
|
|
Loading…
Reference in a new issue