Skip to content

tool: checkfds, open on null device - #22716

Closed
icing wants to merge 2 commits into
curl:masterfrom
icing:tool-checkfds-dev-null
Closed

icing wants to merge 2 commits into
curl:masterfrom
icing:tool-checkfds-dev-null

Conversation

@icing

@icing icing commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

When stdin/out/err are closed on tool start, checkfds() tries to fill them by invoking pipe() which is may allocate file descriptors in an unwanted order and may create a pipe between stdout and stdin which is not what we want.

Use 'nul' on Windows or '/dev/null' if HAVE_PIPE is defined to open the closed descriptors.

Caveat: I am not 100% sure that HAVE_PIPE implies that /dev/null works, but it seems likely?

When stdin/out/err are closed on tool start, checkfds() tries
to fill them by invoking `pipe()` which is may allocate file
descriptors in an unwanted order and may create a pipe between
stdout and stdin which is not what we want.

Use 'nul' on Windows or '/dev/null' if HAVE_PIPE is defined
to open the closed descriptors.

Caveat: I am not 100% sure that HAVE_PIPE implies that /dev/null
works, but it seems likely?
@icing
icing marked this pull request as draft August 28, 2026 09:48
@bagder
bagder requested a balanced review from Copilot August 28, 2026 09:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Updates startup descriptor recovery to use the platform null device instead of pipes.

Changes:

  • Opens closed stdin, stdout, and stderr on nul or /dev/null.
  • Keeps descriptor direction appropriate for input and output.
Suppressed comments (1)

src/tool_main.c:90

  • DOS builds also use the NUL device, but this guard sends MSDOS builds to /dev/null. The existing platform handling in tests/libtest/lib518.c:33-36 and tests/libtest/lib537.c:30-34 includes both _WIN32 and MSDOS; without the same check here, supported DOS builds with HAVE_PIPE and HAVE_FCNTL fail startup when a standard descriptor is closed.
#ifdef _WIN32

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/tool_main.c Outdated
@icing
icing marked this pull request as ready for review August 28, 2026 12:01
@bagder

bagder commented Aug 28, 2026

Copy link
Copy Markdown
Member

Caveat: I am not 100% sure that HAVE_PIPE implies that /dev/null works, but it seems likely?

Right, but otherwise it fails anyway so it seems that if it against all odds actually causes trouble for someone we should hear about it...

@bagder bagder closed this in 0ebe0e9 Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants