Repository navigation
fix(jobs): ambiguous %?pat jobspec errors instead of resolving (rubash#1302) - #1437
Merged
Merged
Conversation
…U (rubash#1302)
GNU builtins/common.c:689 get_job_spec -> common.c:632 get_job_by_name
counts (job, process) matches and returns DUP_JOB (jobs.h:207) when
more than one fires; the matching p is not advanced before `job` is
assigned, so a match on any stage other than j->pipe is ambiguous with
itself. Rubash's resolve_jobspec returned the newest matching job
silently: `kill -0 %?sleep` with two sleeps returned rc 0 with no
diagnostic, and wait/fg went on to hang on the wrong job.
- JobTable::resolve_jobspec now returns JobspecMatch {Job, Ambiguous,
NoMatch}; get_job_by_name mirrors the C loop: newest-first jobs,
per-stage commands (new JobEntry.stage_commands = GNU's j->pipe
PROCESS texts), strcasestr for %?, STREQN prefix for %name, and the
non-first-stage self-ambiguity quirk. The `%`/`+`/`-` dispatch is
first-byte like common.c:720-738 (%-x, %+x, %%x).
- bash_job_stage_commands splits pipeline stages at registration,
unwrapping !/time like GNU's printed per-process commands.
- kill (kill.def:226-268): ambiguous -> `kill: name: ambiguous job
spec`; operand status now uses GNU's any_succeeded/any_failed
counters — spec diagnostics move neither, so `kill -0 %1 %?dup` is 0
and posix `kill %99`/`kill foo` is 0; non-% operands get sh_badpid
text, numeric operands outside the table take the real pid path.
- wait (wait.def:294-311): ambiguous -> diagnostic + 127, in the
-n/set_waitlist arm (with the trailing "no such job" sh_badjob), the
operand loop, and the all-failed fallback.
- jobs/jobs -x (jobs.def:156-164/execute_list_with_replacements) and
disown (jobs.def:286-291): ambiguous prints the diagnostic AND
sh_badjob.
- fg/bg (fg_bg.def:143-152): ambiguous prints the diagnostic only.
Verified byte-identical stdout/stderr/rc against GNU bash 5.3.20
across kill/kill -0, wait, wait -n, jobs, jobs -x, disown, fg, bg, and
%spec-as-command, for single/double/pipeline/!-pipeline jobs, prefix
and %? forms, case-fold, mixed operands, posix mode, and empty table.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…pectations in #549 (GNU jobs.def:174 -> rc=1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1302 (devin lane fix/p1-1302, captain-verified + regression matrix added).
Root cause: name-jobspec matching never counted matches — first hit won. Now resolve_jobspec -> JobspecMatch{Job, Ambiguous, NoMatch} mirroring the C loop (stage command texts, %? case-folded strcasestr, %name STREQN prefix, %+x/%-x/%% first-byte dispatch). Consumers per GNU: kill (diagnostic only, rc=1 + any_succeeded/any_failed counters per kill.def:265-268), wait/wait -n (127), jobs/disown (diagnostic + no such job, rc=1), fg/bg (diagnostic only), jobs -x (diagnostic + passthrough).
Evidence: 16 script shapes diffed byte-identical (stdout+stderr+rc) vs GNU 5.3.20 (kill/wait/jobs/disown/jobs -x/prefix/fold/posix/exact/current/previous/fg/bg/wait -n/single).
Tests: new tests/issue1302_ambiguous_jobspec_regressions.rs (13 cases, all green); updated 5 stale rc=0 expectations in issue549 file to GNU-verified rc=1 (GNU jobs.def:174 any_failed -> FAILURE; process rc stays 0, builtin status rc=1); lib 716/0; fmt clean.
Note: 2 part_080 procsub tests fail on base (pre-existing persistent->(...) bug, fixed by forthcoming #1336 harvest-hang PR — verified green there). Rebase onto that PR before merge.