DAOS-17688 ddb: Prevent C stdout output truncation when piped or redi…#17701
DAOS-17688 ddb: Prevent C stdout output truncation when piped or redi…#17701
Conversation
|
Ticket title is 'Not possible to use ddb stdout with pipe' |
|
Test stage Build on Leap 15 with Intel-C and TARGET_PREFIX completed with status FAILURE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net//job/daos-stack/job/daos/view/change-requests/job/PR-17701/1/execution/node/282/log |
|
Test stage Build on EL 8 completed with status FAILURE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net//job/daos-stack/job/daos/view/change-requests/job/PR-17701/1/execution/node/320/log |
|
Test stage Build on EL 9 completed with status FAILURE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net//job/daos-stack/job/daos/view/change-requests/job/PR-17701/1/execution/node/312/log |
|
Test stage Build on Leap 15 completed with status FAILURE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net//job/daos-stack/job/daos/view/change-requests/job/PR-17701/1/execution/node/328/log |
…rected Without disabling C stdout buffering, output from C functions such as printf() can be lost or delayed when the ddb command stdout is connected to a pipe or redirected to a file. This is caused by Unix fully-buffering C stdout in such cases, unlike Go's stdout which is always unbuffered. Fix this by calling initCStdout() at startup to disable C stdout buffering, ensuring all C output is flushed immediately regardless of how stdout is connected. Signed-off-by: Cedric Koch-Hofer <cedric.koch-hofer@hpe.com>
ab270c3 to
bc31fc2
Compare
kjacque
left a comment
There was a problem hiding this comment.
Requesting a couple small changes. Otherwise this looks good.
| // - https://stackoverflow.com/questions/1716296/why-does-printf-not-flush-after-the-call-unless-a-newline-is-in-the-format-strin | ||
| // - https://stackoverflow.com/questions/3723795/is-stdout-line-buffered-unbuffered-or-indeterminate-by-default | ||
| // - https://groups.google.com/g/comp.lang.c/c/dvRKt-iuO40# | ||
| func InitCStdout() error { |
There was a problem hiding this comment.
naming suggestion - DisableCStdoutBuffering
The behavior is very specific -- seems like the name should be, too.
| import "C" | ||
| import "github.com/pkg/errors" | ||
|
|
||
| // InitCStdout disables C stdout buffering and must be called before any write to stdout. |
There was a problem hiding this comment.
Best to specify that this is any C code write to stdout, when called from Go code. The comment is otherwise fantastic though, thanks for documenting this workaround well.
Description
Without disabling C stdout buffering, output from C functions such as
printf()can be lost or delayed when the ddb command stdout is connected to a pipe or redirected to a file. This is caused by Unix fully-buffering C stdout in such cases, unlike Go's stdout which is always unbuffered.Fix this by calling
initCStdout()at startup to disable C stdout buffering, ensuring all C output is flushed immediately regardless of how stdout is connected.Steps for the author:
After all prior steps are complete: