feat(uname): implement uname builtin (Linux only, proc-based)#146
feat(uname): implement uname builtin (Linux only, proc-based)#146
Conversation
Add uname command that reads system information from /proc/sys/kernel/ pseudo-files. Supports POSIX flags: -s (kernel name, default), -n (hostname), -r (release), -v (version), -m (machine), -a (all). The proc path is configurable via --proc-path / interp.ProcPath(), supporting containerized environments where /proc is mounted at /host/proc or similar. Adds ProcPath() accessor to ProcProvider so builtins can construct proc file paths from the configured base path. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move proc file reading into ProcProvider.ReadKernelFile(), following the same pattern as ps which delegates to procinfo. The uname builtin now has zero direct os package usage — all proc I/O goes through the ProcProvider abstraction. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Previously showed a confusing "cannot read ostype: no such file" error on macOS/Windows. Now checks runtime.GOOS first and prints "uname: not supported on darwin (Linux only)". Tests skip proc-dependent cases on non-Linux, with a dedicated TestUnameNonLinuxPlatform test verifying the error message. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Go tests (Linux-only via requireLinux): - Duplicate flags (-ss), all flags explicit (-snrvm), flag order independence (-mrvns), -a overrides individual flags - Partial proc tree (success and failure paths) - Whitespace trimming in proc values, empty proc file - Pipe integration, variable capture via command substitution - Context cancellation All-platform tests: - Help via -h and --help, stderr empty on help - Extra positional arguments ignored (POSIX behavior) YAML scenarios: - errors/unknown_flag — rejects unknown flags - basic/help — --help prints usage to stdout Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@codex conduct a comprehensive security and code review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6244031185
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
GNU uname rejects extra operands with exit 1: uname: extra operand 'foo' Our implementation was silently ignoring them. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@codex conduct a comprehensive security and code review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 69d2faa978
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Replace unbounded os.ReadFile with os.Open + io.LimitReader(4096). Prevents DoS if --proc-path points at a large file or FIFO instead of actual proc pseudo-files. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The test helper returned exit code 0 when runner.Run failed with a context cancellation error (no ExitStatus unwrapped). Now returns 1 for cancelled contexts, fixing TestUnameContextCancellation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@codex conduct a comprehensive security and code review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a90396b25c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex conduct a comprehensive security and code review. ignore the symlink kernel file reads in uname reads. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a90396b25c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Check file type via fstat after open — reject FIFOs, sockets, etc. that could block indefinitely. Allow regular files and char devices (proc pseudo-files may appear as char devices on some configs). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@codex conduct a comprehensive security and code review. ignore the symlink kernel file reads in uname reads. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4a6940b38c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
os.Open on a FIFO blocks in open(2) before reaching the fstat type check, causing uname to hang when --proc-path points at a tree with mkfifo'd entries. Move the type check to os.Stat before os.Open so FIFOs are rejected without blocking. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@codex conduct a comprehensive security and code review. ignore the symlink kernel file reads in uname reads. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7bf18fac5d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The previous stat-then-open approach had a TOCTOU gap where an attacker could swap a regular file for a FIFO between the stat and open calls. Now opens with O_NONBLOCK (prevents blocking on FIFOs), then validates file type via fstat on the opened fd — atomic check. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@codex conduct a comprehensive security and code review. ignore the symlink kernel file reads in uname reads. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 70d0acd793
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Per AlexandreYang's review: move ReadKernelFile logic into a new builtins/internal/procsyskernel package for consistency with the existing procinfo, procnetsocket, and procnetroute internal packages. ProcProvider.ReadKernelFile now delegates to procsyskernel.ReadFile. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@codex conduct a comprehensive security and code review. ignore the symlink kernel file reads in uname reads. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 98f63209d8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Add the same ".." traversal guard used by procnetroute and procnetsocket. Rejects paths like "/proc/../etc/passwd" before filepath.Clean can normalize them away. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
BoolP("s","s",...) registered --s as a long form. GNU uname --v prints
the coreutils version (not kernel version), making --v incompatible.
Use descriptive long names matching GNU coreutils:
--kernel-name, --nodename, --kernel-release, --kernel-version,
--machine, --all
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@codex conduct a comprehensive security and code review. ignore the symlink kernel file reads in uname reads. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f1a0208d06
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
ReadFile's name parameter is currently hardcoded from uname.go, but the API is exported. Reject absolute paths, "..", and path separators in name to prevent path escape via the exported ReadKernelFile API. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add "Try 'uname --help' for more information." line to match GNU coreutils error format. Remove skip_assert_against_bash since uname is available on Ubuntu CI runners. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@codex conduct a comprehensive security and code review. ignore the symlink kernel file reads in uname reads. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0b2917e025
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
When /proc/sys/kernel/arch is unavailable (older kernels, restricted environments), fall back to runtime.GOARCH mapped to Linux kernel machine names (amd64→x86_64, arm64→aarch64, 386→i686, etc.). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@codex conduct a comprehensive security and code review. ignore the symlink kernel file reads in uname reads. |
runtime.GOARCH returns the compile-time target architecture, not the host system's architecture. With --proc-path pointing at a remote host's proc tree, the fallback would silently return wrong data. The proc file is the only correct source; if missing, fail honestly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c02f36e7a1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Last 2.6 LTS (2.6.32) reached EOL February 2016. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Help now shows both short and long forms (e.g. -s, --kernel-name) matching the GNU coreutils style. Updated help scenario assertions to verify long option names are present. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… scenarios - unknown_flag: pflag error format differs from GNU coreutils - help: GNU includes flags we don't support (-p, -i, -o, --version) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@codex conduct a comprehensive security and code review. ignore the symlink kernel file reads in uname reads. |
|
Codex Review: Didn't find any major issues. 🎉 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
| @@ -0,0 +1,11 @@ | |||
| # skip: GNU uname --help includes flags we don't support (-p, -i, -o, --version) | |||
There was a problem hiding this comment.
Should we have scenario tests for each of the flags?
There was a problem hiding this comment.
[Claude Opus 4.6] Cannot add scenario tests for flag output — the scenario test framework has no platform-skip mechanism, and uname reads from /proc (Linux-only). Scenarios fail on macOS and Windows CI runners. This is the same limitation documented in AGENTS.md for ip route:
"ip route show/ip route get happy-path scenario tests cannot be added. The scenario test framework has no platform-skip mechanism."
Flag coverage is in the Go tests (builtins/tests/uname/uname_test.go) which use requireLinux(t) to skip gracefully on non-Linux. Every flag (-s, -n, -r, -v, -m, -a) plus combined flags, flag ordering, and edge cases are covered there with a fake proc tree.
Summary
unamebuiltin that reads system information from/proc/sys/kernel/pseudo-files--proc-path/interp.ProcPath()(supports/host/procfor containers)ProcPath()accessor toProcProviderFlags (POSIX)
-ssys/kernel/ostype-nsys/kernel/hostname-rsys/kernel/osrelease-vsys/kernel/version-msys/kernel/arch-a-hTest plan
go test ./builtins/tests/uname/...passesgo test ./allowedsymbols/...passesgo test ./...full suite passes🤖 Generated with Claude Code