Skip to content

fix(libcontainer): open /dev/null read-write in reopen_dev_null - #3947

Merged
utam0k merged 2 commits into
youki-dev:mainfrom
utam0k:fix-reopen-dev-null
Nov 29, 2026
Merged

utam0k merged 2 commits into
youki-dev:mainfrom
utam0k:fix-reopen-dev-null

Conversation

@utam0k

@utam0k utam0k commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Description

A container cannot write to stdout or stderr when that fd is the host's /dev/null. reopen_dev_null() swaps such fds for the container's /dev/null, but it opens that file read-only. Every write then fails with EBADF. On a GitHub runner, with process.args set to sh -c "echo Hi, my PID is $$; echo Bye Bye":

$ sudo ./youki run -b bundle t1 >/dev/null 2>/tmp/e1; echo "stdout=null rc=$?"; cat /tmp/e1
stdout=null rc=1
sh: write error: Bad file descriptor
sh: write error: Bad file descriptor

This opens /dev/null read-write, as runc's reOpenDevNull does.

I found it while fixing the benchmark workflow (#3948). hyperfine sends the benchmarked command's output to /dev/null by default.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Testing

  • Added new unit tests

test_reopen_dev_null_keeps_stdout_writable points stdout at a write-only /dev/null in a child process, calls reopen_dev_null(), and writes to stdout. The first commit adds the test, and it fails with EBADF: Bad file number. The second commit fixes the open, and the test passes.

Also ran cargo test -p libcontainer --lib process::init, cargo +nightly fmt --check -p libcontainer, and cargo clippy -p libcontainer --all-targets -- -D warnings.

Additional Context

AI-assisted.

@utam0k
utam0k requested a review from a team November 28, 2026 23:41
@utam0k
utam0k merged commit ddbb66e into youki-dev:main Nov 29, 2026
36 checks passed
@youki-dev-bot youki-dev-bot Bot mentioned this pull request Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants