Skip to content

DAOS-17688 ddb: Prevent C stdout output truncation when piped or redi…#17701

Open
knard38 wants to merge 1 commit intomasterfrom
ckochhof/fix/ee5bfa7b2/daos-17688/patch-001
Open

DAOS-17688 ddb: Prevent C stdout output truncation when piped or redi…#17701
knard38 wants to merge 1 commit intomasterfrom
ckochhof/fix/ee5bfa7b2/daos-17688/patch-001

Conversation

@knard38
Copy link
Contributor

@knard38 knard38 commented Mar 13, 2026

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:

  • Commit message follows the guidelines.
  • Appropriate Features or Test-tag pragmas were used.
  • Appropriate Functional Test Stages were run.
  • At least two positive code reviews including at least one code owner from each category referenced in the PR.
  • Testing is complete. If necessary, forced-landing label added and a reason added in a comment.

After all prior steps are complete:

  • Gatekeeper requested (daos-gatekeeper added as a reviewer).

@knard38 knard38 self-assigned this Mar 13, 2026
@github-actions
Copy link

Ticket title is 'Not possible to use ddb stdout with pipe'
Status is 'In Progress'
https://daosio.atlassian.net/browse/DAOS-17688

@knard38 knard38 marked this pull request as ready for review March 13, 2026 15:13
@knard38 knard38 requested review from a team as code owners March 13, 2026 15:13
@daosbuild3
Copy link
Collaborator

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

@daosbuild3
Copy link
Collaborator

@daosbuild3
Copy link
Collaborator

@daosbuild3
Copy link
Collaborator

…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>
@knard38 knard38 force-pushed the ckochhof/fix/ee5bfa7b2/daos-17688/patch-001 branch from ab270c3 to bc31fc2 Compare March 13, 2026 15:56
Copy link
Contributor

@kjacque kjacque left a comment

Choose a reason for hiding this comment

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

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants