From a27f6153503921027de867814e3ba27ffef55a50 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Fri, 19 Sep 2025 14:19:26 +0200 Subject: [PATCH] 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 26116b477ed629be35d3bd50896ac9a1bb8ff9e1) --- src/builtins/bg.rs | 11 ++++++----- tests/checks/job-control-noninteractive.fish | 3 +++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/builtins/bg.rs b/src/builtins/bg.rs index 10373603a..33cd32aa0 100644 --- a/src/builtins/bg.rs +++ b/src/builtins/bg.rs @@ -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; } diff --git a/tests/checks/job-control-noninteractive.fish b/tests/checks/job-control-noninteractive.fish index da4566306..a2cc3c716 100644 --- a/tests/checks/job-control-noninteractive.fish +++ b/tests/checks/job-control-noninteractive.fish @@ -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