diff options
author | Ron Yorston <rmy@pobox.com> | 2024-04-06 08:58:12 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-04-06 08:58:12 +0100 |
commit | 54dbf0fa510afcd3058a5da66e1c4a390c2ba89b (patch) | |
tree | 2ed159e1e803ed720852701a9dcfb3d420e29bd4 | |
parent | abdfde6ba63622c7d0fb9b42b7f38e40ba5619b2 (diff) | |
download | busybox-w32-54dbf0fa510afcd3058a5da66e1c4a390c2ba89b.tar.gz busybox-w32-54dbf0fa510afcd3058a5da66e1c4a390c2ba89b.tar.bz2 busybox-w32-54dbf0fa510afcd3058a5da66e1c4a390c2ba89b.zip |
time: mitigation for interleaved output
When the 'time' applet is run in a pipeline, like so:
time seq 1 10 | tail -2
stdout from 'tail' and stderr from 'time' can be interleaved.
This is particularly the case with the ConEmu terminal emulator.
The interleaving can be reduced, though not eliminated, by
buffering the output of 'time'.
Adds 40-44 bytes.
(GitHub issue #396)
-rw-r--r-- | miscutils/time.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/miscutils/time.c b/miscutils/time.c index e24221341..09a474979 100644 --- a/miscutils/time.c +++ b/miscutils/time.c | |||
@@ -471,6 +471,9 @@ int time_main(int argc UNUSED_PARAM, char **argv) | |||
471 | /* $TIME has lowest prio (-v,-p,-f FMT override it) */ | 471 | /* $TIME has lowest prio (-v,-p,-f FMT override it) */ |
472 | const char *output_format = getenv("TIME") ? : default_format; | 472 | const char *output_format = getenv("TIME") ? : default_format; |
473 | char *output_filename; | 473 | char *output_filename; |
474 | #if ENABLE_PLATFORM_MINGW32 | ||
475 | char buffer[256]; | ||
476 | #endif | ||
474 | int output_fd; | 477 | int output_fd; |
475 | int opt; | 478 | int opt; |
476 | int ex; | 479 | int ex; |
@@ -524,6 +527,9 @@ int time_main(int argc UNUSED_PARAM, char **argv) | |||
524 | 527 | ||
525 | /* Cheat. printf's are shorter :) */ | 528 | /* Cheat. printf's are shorter :) */ |
526 | xdup2(output_fd, STDOUT_FILENO); | 529 | xdup2(output_fd, STDOUT_FILENO); |
530 | #if ENABLE_PLATFORM_MINGW32 | ||
531 | setvbuf(stdout, buffer, _IOFBF, sizeof(buffer)); | ||
532 | #endif | ||
527 | summarize(output_format, argv, &res); | 533 | summarize(output_format, argv, &res); |
528 | 534 | ||
529 | ex = WEXITSTATUS(res.waitstatus); | 535 | ex = WEXITSTATUS(res.waitstatus); |