You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Should uutils-coreutils respect stdbuf buffering options? #7967
Context: while trying to implement a regression-test for #6591 I noticed that testing stdbuf with some GNU coreutils utilities work, but fails with uutils coreutils utilities.
stdbuf -o works by changing the buffering option. Specifically by preloading libstdbuf.so which contains an overriden version of setvbuf. This function takes precedence over the normal setvbuf function of the libc library.
when C programs call IO functions like printf, setvbuf() gets called
when Rust programs call IO functions like print or println, setvbuf() does not get called, and thus stdbuf -o has no effect (at least this is what my testing is showing. See also this explanation
in theory, the buffering behavior of C programs could be emulated in rust e.g. by reading the value of the environment variable "_STDBUF_O" which is set by stdbuf, or by somehow calling setvbuf for IO.
Should this emulation be implemented in uutils-coreutils? I checked the POSIX specification, and have not found an explicit specification of the buffering behavior for e.g. "cut", and it seems to be rather part of the C standard. So as far as I understand uutils-coreutils could be POSIX compliant without this behavior, but it would be a small difference with GNU coreutils.
If stdbuf has an effect, you should see nothing in the stdout of process 1 (happens with GNU coreutils). If stdbuf has no effect, you should see "A" in the stdout of process 1 (happens with uutils coreutils).
I would prefer we are doing the same as GNU. IMHO, it is the gold standard (more than the POSIX specification)
but I understand that might be super hard to do
Reacted by Chow Loong Jin
Reacted by Etienne Cordonnier and Victor Prokhorov
See also rust-lang/rust#60673 . I think it may not make sense to reopen this ticket as there is not much we can do at the moment. But rust-lang/rust#60673 discusses making line-buffering configrable in the rust standard library, at which point I hope it would be easy to make it work with uutil stdbuf.
Assuming an ACP was approved and the implementation landed, buffering mode could be changed at runtime in Rust via shared state inside libstd. But this only works when libstdbuf.so and the target binary are both linked against the same libstd instance, i.e. both built with -C prefer-dynamic, so they share a single OnceLock within that process. With static linking each binary embeds its own copy of libstd, so the preloaded library and the target binary end up with separate state and the mode change has no effect.
Given that matching GNU behavior is the goal, would dynamically linked builds be acceptable, at least optionally, or is the preference to remain on static builds and pursue a different, Rust-native mechanism for buffering control?
In other words, is matching GNU stdbuf behavior considered important enough to justify relying on shared libstd via dynamic linking? @sylvestre, @Ecordonnier
If we can achieve same performance with buffered I/O without buffering, we don't need stdbuf. Right? I think few utils supporting zero-copy are already doing it by default (at least on Linux) and tail -f can do that at least for.
Activity
sylvestre commentedon Jun 2, 2025
I would prefer we are doing the same as GNU. IMHO, it is the gold standard (more than the POSIX specification)
but I understand that might be super hard to do
Ecordonnier commentedon Jun 7, 2025
OK. Thanks for your feedback!
Work with `stdbuf` environment variables
Ecordonnier commentedon Dec 5, 2025
See also rust-lang/rust#60673 . I think it may not make sense to reopen this ticket as there is not much we can do at the moment. But rust-lang/rust#60673 discusses making line-buffering configrable in the rust standard library, at which point I hope it would be easy to make it work with uutil stdbuf.
victor-prokhorov commentedon Mar 28, 2026
Assuming an ACP was approved and the implementation landed, buffering mode could be changed at runtime in Rust via shared state inside libstd. But this only works when libstdbuf.so and the target binary are both linked against the same libstd instance, i.e. both built with
-C prefer-dynamic, so they share a singleOnceLockwithin that process. With static linking each binary embeds its own copy of libstd, so the preloaded library and the target binary end up with separate state and the mode change has no effect.Given that matching GNU behavior is the goal, would dynamically linked builds be acceptable, at least optionally, or is the preference to remain on static builds and pursue a different, Rust-native mechanism for buffering control?
In other words, is matching GNU stdbuf behavior considered important enough to justify relying on shared libstd via dynamic linking? @sylvestre, @Ecordonnier
oech3 commentedon Apr 27, 2026
If we can achieve same performance with buffered I/O without buffering, we don't need
stdbuf. Right? I think few utils supporting zero-copy are already doing it by default (at least on Linux) andtail -fcan do that at least for.oech3 commentedon May 16, 2026
If we want to support Windows without cygwin dll dep, we need to parse env vars.
oech3 commentedon Sep 30, 2026
I don't think it is possible. But can we mimic
stdbuf's buffering using ptrace? @BAMF0