Skip to content

fix: omit coproc name from jobs display for simple bodies (#1645) - #1699

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix-1645-jobs-coproc-name
Oct 26, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix-1645-jobs-coproc-name

Conversation

@arookieofc

Copy link
Copy Markdown
Member

Fixes #1645.

Bug

After a simple-command coproc, jobs printed the auto-generated name (coproc COPROC sleep 5 &); GNU prints coproc sleep 5 &. Cosmetic only; job control itself agreed.

Root cause (GNU source)

Vendored third_party/bash/print_cmd.c, cm_coproc case (5.3.20):

cprintf ("coproc ");
if (command->value.Coproc->command->type != cm_simple)
  cprintf ("%s ", command->value.Coproc->name);

The name is printed ONLY when the body is not a simple command. Rubash's coproc_command_source_text always printed it (defaulting an unnamed coproc to COPROC) — and its comment even claimed GNU always prints the name. That matches bash 5.2's print code, not 5.3.20's, so the local system bash (5.2) is not the oracle here; the vendored 5.3.20 source and the issue's 5.3.20 measurements are.

Change

src/executor/command_text.rs: print the name only when body_kind != SimpleCommand. Consequences, all verified against the 5.3.20 rule:

  • coproc sleep 5 → coproc sleep 5 & (was coproc COPROC sleep 5 &)
  • coproc { sleep 5; } → coproc COPROC { sleep 5; } & (unchanged, group form already agreed)
  • coproc C1 { sleep 5; } → coproc C1 { sleep 5; } & (unchanged)
  • coproc FOO sleep 5 → coproc FOO sleep 5 & (was coproc COPROC FOO sleep 5 &; there is no COPROC WORD simple_command production, so FOO is argv[0], not a name)
  • coproc FOO { sleep 5; } → coproc FOO { sleep 5; } & (unchanged)

The rendering feeds jobs, jobs -l, and every other command display, matching GNU's single print_command. Round-trip re-parse is unaffected: simple bodies never carried a real name to lose, and compound bodies keep theirs.

Verification

Known adjacent gap, not fixed here

A subshell coproc body still renders as { sleep 5; } instead of GNU's ( sleep 5 ) — the compound-body shape rendering in the same function, separate from the name question.

GNU print_cmd.c `cm_coproc` (5.3.20) prints the coproc name ONLY
when the body is not a simple command: `coproc sleep 5` displays as
`coproc sleep 5 &`, while `coproc { sleep 5; }` / `coproc C1
{ sleep 5; }` display with their names. Rubash's
coproc_command_source_text always printed the name (defaulting an
unnamed coproc to COPROC), so `jobs` showed `coproc COPROC sleep 5
&`. The old comment here claimed GNU always prints the name; that
matches bash 5.2's print code, not 5.3.20's.

The fix prints the name only when body_kind != SimpleCommand.
There is no `COPROC WORD simple_command` production, so a simple
body never carries a real name: `coproc FOO sleep 5` is an unnamed
coproc of [FOO, sleep, 5] and now displays as `coproc FOO sleep 5
&` (was `coproc COPROC FOO sleep 5 &`). Compound bodies are
unchanged. The rendering feeds jobs, jobs -l, and every other
command display, matching GNU's single print_command; round-trip
re-parse is unaffected (simple bodies never had a name to lose).

Tests: new tests/issue1645_jobs_coproc_name.rs (7 cases: simple,
jobs -l, named/unnamed group, FOO-before-simple-body,
FOO-before-group, disown control).

Known adjacent gap, NOT fixed here: a subshell coproc body still
renders as `{ sleep 5; }` instead of GNU's `( sleep 5 )` — the
compound-body shape rendering in the same function, separate from
the name question.
@caomengxuan666
caomengxuan666 merged commit 8c5b2f3 into master Oct 26, 2026
7 of 10 checks passed
@caomengxuan666
caomengxuan666 deleted the fix-1645-jobs-coproc-name branch October 30, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] jobs prints auto-name COPROC for simple-command coproc; GNU omits it (group form agrees)

2 participants