Fix crash on "bg" of non-job-controlled job

fish -c 'sleep 1 & bg %1' is supposed to fail because the job is not
under job control.

When we try to print the failure, we accidentally still
hold a borrow of the job list.  This blows up because we use
"builtin_print_help_error()" to print the failure message; that
function runs "job_reap()" which wants an exclusive borrow of the
job list. Let's drop our job list earlier.

(cherry picked from commit 26116b477e)
This commit is contained in:
Johannes Altmanninger
2025-09-19 14:19:26 +02:00
parent 46ce8a1d2f
commit a27f615350
2 changed files with 9 additions and 5 deletions

View File

@@ -17,12 +17,13 @@ fn send_to_bg(
let err = {
let job = &jobs[job_pos];
wgettext_fmt!(
"%ls: Can't put job %s, '%ls' to background because it is not under job control\n",
cmd,
job.job_id().to_wstring(),
job.command()
)
"%ls: Can't put job %s, '%ls' to background because it is not under job control\n",
cmd,
job.job_id().to_wstring(),
job.command()
)
};
drop(jobs);
builtin_print_help_error(parser, streams, cmd, &err);
return STATUS_CMD_ERROR;
}

View File

@@ -18,3 +18,6 @@ or echo "pgroups were the same, job control did not work"
$fish -c 'status job-control full ; $fth report_foreground' &
wait
#CHECKERR: background
$fish -c 'sleep .2 & bg %1'
#CHECKERR: bg: Can't put job 1, 'sleep .2 &' to background because it is not under job control