Skip to content

stdbuf: fix stdio getters in libstdbuf - #15480

Merged
sylvestre merged 5 commits into
uutils:mainfrom
Ecordonnier:eco/stdbuf-cygwin-stderr-getter
Oct 24, 2026
Merged

sylvestre merged 5 commits into
uutils:mainfrom
Ecordonnier:eco/stdbuf-cygwin-stderr-getter

Conversation

@Ecordonnier

@Ecordonnier Ecordonnier commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator
  • On Cygwin, __stdbuf_get_stderr returned _stdin, so stdbuf -e changed stdin's buffering ( Introduced in 54ba74b ("Add more Cygwin support", Add more Cygwin support #9686). )
  • On Apple and FreeBSD, __std{in,out,err}p were declared as functions, but they are variables, so calling them crashed (SIGBUS on macOS).

The new unit test checks that each getter returns its own stream (fd 0, 1, 2).

__stdbuf_get_stderr read _stdin from the reent struct on cygwin, so
stdbuf -e changed the buffering of stdin instead of stderr.

Introduced in 54ba74b ("Add more Cygwin support", uutils#9686).
Copilot AI balanced review requested due to automatic review settings October 18, 2026 15:22
@Ecordonnier

Copy link
Copy Markdown
Collaborator Author

@500-internal-server-error FYI

Copilot AI left a comment

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.

🟡 Changes recommended

The bug fix lacks the regression test required by repository guidelines.

1 open issue
What changed in this PR

Fixes Cygwin’s stderr getter so stdbuf -e changes stderr buffering rather than stdin buffering.

Changes:

  • Returns _stderr instead of _stdin from the Cygwin reentrancy structure.
File Description
src/​uu/​stdbuf/​src/​libstdbuf/​src/​libstdbuf.rs Corrects the Cygwin stderr stream pointer.

Review effort: Balanced

Comment thread src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs
@500-internal-server-error

Copy link
Copy Markdown
Contributor

__stdbuf_get_stderr read _stdin from the reent struct on cygwin, so stdbuf -e changed the buffering of stdin instead of stderr.

Whoops, it looks like I forgot to replace this one when copy pasting... apologies :(

Check that the stdin, stdout and stderr getters give file descriptors
0, 1 and 2. This would have caught the cygwin stderr getter returning
stdin. Enable the unit tests of libstdbuf for this.
Copilot AI balanced review requested due to automatic review settings October 18, 2026 15:54
@Ecordonnier

Copy link
Copy Markdown
Collaborator Author

__stdbuf_get_stderr read _stdin from the reent struct on cygwin, so stdbuf -e changed the buffering of stdin instead of stderr.

Whoops, it looks like I forgot to replace this one when copy pasting... apologies :(

No problem. I just thought you may want to cherry-pick this if you have a use-case where you're using stdbuf on cygwin.

Copilot AI left a comment

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues

Review effort: Lite

Comment thread src/uu/stdbuf/src/libstdbuf/Cargo.toml
@sylvestre

Copy link
Copy Markdown
Contributor

Seems that the mac CI is sad

__stdinp, __stdoutp and __stderrp are data variables, not functions.
Calling them jumped into data and crashed with SIGBUS on macOS.
Copilot AI balanced review requested due to automatic review settings October 19, 2026 10:59

Copilot AI left a comment

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

5 open issues

Review effort: Lite

Comment thread src/uu/stdbuf/src/libstdbuf/Cargo.toml
Comment thread src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs
Comment on lines +261 to +263
assert_eq!(fileno(__stdbuf_get_stdin()), 0);
assert_eq!(fileno(__stdbuf_get_stdout()), 1);
assert_eq!(fileno(__stdbuf_get_stderr()), 2);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

could also use constants like: libc::STDIN_FILENO

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

OK. I added a commit using the libc constants.

@Ecordonnier Ecordonnier changed the title stdbuf: return stderr from the cygwin stderr getter stdbuf: fix stdio getters in libstdbuf Oct 19, 2026
Copilot AI balanced review requested due to automatic review settings October 19, 2026 13:48

Copilot AI left a comment

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

5 open issues

Review effort: Lite

Copilot AI balanced review requested due to automatic review settings October 19, 2026 14:04

Copilot AI left a comment

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.

[lib]
name = "stdbuf"
path = "src/libstdbuf.rs"
crate-type = ["cdylib"]
Comment on lines +27 to +29
static mut __stdinp: *mut FILE;
}
unsafe { __stdinp() }
unsafe { __stdinp }
Copilot AI balanced review requested due to automatic review settings October 19, 2026 16:31

Copilot AI left a comment

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.

@Ecordonnier

Copy link
Copy Markdown
Collaborator Author

Seems that the mac CI is sad

The Mac CI is fixed now.

@sylvestre
sylvestre merged commit dbaeb4c into uutils:main Oct 24, 2026
97 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

@Ecordonnier
Ecordonnier deleted the eco/stdbuf-cygwin-stderr-getter branch October 24, 2026 20:19
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.

5 participants