Commit 7f642b0
authored
fix(redirect): suppress stderr from builtins with 2>/dev/null (#1138)
## Summary
- Fix compound commands with output redirects (e.g. `{ cmd; }
2>/dev/null`) leaking stderr via output_callback before
`apply_redirections` ran
- Fix glob error sentinel path in `execute_simple_command` returning
early without calling `apply_redirections`
## What
Two bugs caused `2>/dev/null` to not suppress stderr from builtins:
1. **Streaming callback leak**: When `output_callback` is set (streaming
mode), compound commands like `{ ls /nonexistent; } 2>/dev/null` emitted
stderr via the callback during body execution, before the outer redirect
could suppress it. Fix: suspend `output_callback` during compound body
execution when output redirects are present.
2. **Glob sentinel bypass**: When `shopt -s failglob` is enabled and a
glob has no matches, the error sentinel path returned
`ExecResult::err()` directly without routing through
`apply_redirections`. Fix: pass the error result through
`apply_redirections`.
## Tests
- Unit test: `test_stderr_redirect_devnull_simple_and_compound` (simple,
compound, &>, failglob)
- Streaming test: `test_stderr_redirect_devnull_streaming` (compound +
callback)
- Spec tests: `redirect_stderr_suppress_ls`,
`redirect_stderr_suppress_compound`, `redirect_combined_suppress_ls`
Closes #11161 parent eb874b7 commit 7f642b0
File tree
3 files changed
+99
-1
lines changed- crates/bashkit
- src
- interpreter
- tests/spec_cases/bash
3 files changed
+99
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1367 | 1367 | | |
1368 | 1368 | | |
1369 | 1369 | | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
1370 | 1386 | | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
1371 | 1393 | | |
1372 | 1394 | | |
1373 | 1395 | | |
| |||
3593 | 3615 | | |
3594 | 3616 | | |
3595 | 3617 | | |
3596 | | - | |
| 3618 | + | |
| 3619 | + | |
3597 | 3620 | | |
3598 | 3621 | | |
3599 | 3622 | | |
| |||
10853 | 10876 | | |
10854 | 10877 | | |
10855 | 10878 | | |
| 10879 | + | |
| 10880 | + | |
| 10881 | + | |
| 10882 | + | |
| 10883 | + | |
| 10884 | + | |
| 10885 | + | |
| 10886 | + | |
| 10887 | + | |
| 10888 | + | |
| 10889 | + | |
| 10890 | + | |
| 10891 | + | |
| 10892 | + | |
| 10893 | + | |
| 10894 | + | |
| 10895 | + | |
| 10896 | + | |
| 10897 | + | |
| 10898 | + | |
| 10899 | + | |
| 10900 | + | |
10856 | 10901 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5410 | 5410 | | |
5411 | 5411 | | |
5412 | 5412 | | |
| 5413 | + | |
| 5414 | + | |
| 5415 | + | |
| 5416 | + | |
| 5417 | + | |
| 5418 | + | |
| 5419 | + | |
| 5420 | + | |
| 5421 | + | |
| 5422 | + | |
| 5423 | + | |
| 5424 | + | |
| 5425 | + | |
| 5426 | + | |
| 5427 | + | |
| 5428 | + | |
| 5429 | + | |
| 5430 | + | |
| 5431 | + | |
| 5432 | + | |
| 5433 | + | |
| 5434 | + | |
| 5435 | + | |
| 5436 | + | |
| 5437 | + | |
| 5438 | + | |
| 5439 | + | |
| 5440 | + | |
| 5441 | + | |
5413 | 5442 | | |
Lines changed: 24 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
126 | 150 | | |
127 | 151 | | |
128 | 152 | | |
| |||
0 commit comments