Skip to content

split: exit with the --filter command's status and stop at the first failure - #16492

Open
binhvq wants to merge 2 commits into
uutils:mainfrom
binhvq:split-filter-exit-status
Open

binhvq wants to merge 2 commits into
uutils:mainfrom
binhvq:split-filter-exit-status

Conversation

@binhvq

@binhvq binhvq commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

When a --filter command failed, split printed "Shell process returned N", ran the filter for the remaining chunks anyway and exited with 1.

Now, like GNU, split waits for each filter before opening the next output file, reports with FILE=..., exit N from command: CMD (or signal NAME) and exits right away with the command's status, or 128+N for a signal. A filter killed by SIGPIPE is not treated as an error.

Closes #16491

@codspeed

codspeed Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 3.71%

1 warning

⚠️ 5 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚡ 2 improved benchmarks
✅ 8 untouched benchmarks
⏩ 476 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ CPU Simulation split_lines 4.6 ms 4.5 ms +3.88%
⚡ CPU Simulation split_numeric_suffix 4.9 ms 4.7 ms +3.55%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing binhvq:split-filter-exit-status (4321927) with main (ab69b86)2

Open in CodSpeed

Footnotes

  1. 476 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (a8209e0) during the generation of this report, so ab69b86 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/misc/usage_vs_getopt (fails in this run but passes in the 'main' branch)

Comment thread src/uu/split/src/platform/unix.rs Outdated
return;
};
show_error!("{message}");
std::process::exit(code);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't use std::process::exit, could finish() return a UResult with USimpleError::new(code, message) and let it propagate?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finish() now returns a UResult with USimpleError::new(code, message), and the writers and line_bytes propagate it.

Comment thread src/uu/split/src/platform/unix.rs Outdated
let _stdin = self.shell_process.stdin.as_mut();
}
let exit_status = self
self.finish();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exiting the process from a Drop is risky, with -n r/3 the other filters are never waited for

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop now only waits for the command, without reporting. For -n, all filters are waited for at the end and the first failure is returned, which is what GNU does with r/N.

Comment thread src/uu/split/src/platform/unix.rs Outdated
(message, code)
} else if let Some(signal) = status.signal() {
let name = signal_name(signal);
if name == "PIPE" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comparing the signal number with SIGPIPE would be simpler than matching the name, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it compares with libc::SIGPIPE now.

}
}

#[cfg(not(target_os = "fuchsia"))]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the fuchsia variant? signal_name_by_value already falls back

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uucore::signals is only built on the OS list in uucore/src/lib/lib.rs, and fuchsia is not in it, so it would not compile there. env does the same with not(target_os = "fuchsia").

#[case::bytes("-b2")]
#[case::line_bytes("-C2")]
#[cfg(unix)]
fn test_filter_exit_status_stops_split(#[case] mode: &str) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add a case with -n r/2 too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test_filter_exit_status_round_robin with -n r/2, where all filters fail or only the second one does.

@sylvestre

Copy link
Copy Markdown
Contributor

thanks for tackling this!
This can't land while it uses std::process::exit, including from Drop. Please return the error with the command's code instead.
Please also squash the 4 commits into one.

@binhvq

binhvq commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

No more std::process::exit, the error comes back with the command's code. About squashing: would a squash merge work for you? Otherwise I can squash before it goes in.

@sylvestre

Copy link
Copy Markdown
Contributor

thanks for picking this up!
the Tests job is still red, could you please check whether it's one of the new filter signal tests?
and please squash the commits into one before it lands.

@binhvq

binhvq commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

The red Tests job is OpenBSD: all the split filter tests pass there, including the signal ones; it fails later in the uucore doctest with missing rlibs (E0463), like other PRs. Will squash once it is otherwise ready.

fn test_filter_exit_status_stops_split(#[case] mode: &str) {
let (at, mut ucmd) = at_and_ucmd!();
at.write("in", "a\nb\nc\n");
let filter = "cat > /dev/null; echo $FILE >> calls; exit 5";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add a case where the filter doesn't read its input, like exit 5 alone? also with -n 2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test_filter_exit_status_without_reading_input with exit 5 alone for -l, -b, -C and -n 2. The -n 2 case failed with split: Broken pipe, because that path wrote to the filter without ignoring the closed pipe, so I fixed it too.

@github-actions

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.49 MB (+108 KB, +0.07%)

Significant per-binary changes:
  env     1.20 MB ->    1.28 MB  (+80 KB, +6.51%)

@binhvq
binhvq force-pushed the split-filter-exit-status branch from 9db74ea to 867c177 Compare November 21, 2026 11:32
@binhvq

binhvq commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Squashed into one commit, no code change.

@sylvestre
sylvestre force-pushed the split-filter-exit-status branch 2 times, most recently from 0f951b4 to 0b23d4b Compare November 21, 2026 23:23
…failure

Wait for each filter before opening the next output file, report 'with FILE=..., exit N from command: CMD' (or 'signal NAME') and exit with the command's status, or 128+N for a signal. A filter killed by SIGPIPE is not treated as an error.
@sylvestre
sylvestre force-pushed the split-filter-exit-status branch from 0b23d4b to 5ae537b Compare November 24, 2026 00:55

This branch has not been deployed

No deployments
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.

split: --filter does not propagate the command's exit status and keeps going after a failure

2 participants