Skip to content

argv[0] in WASIX subprocesses should resolve to the atom rather than the full command#6516

Draft
Arshia001 wants to merge 3 commits intomainfrom
fix/command-exec-atom-name
Draft

argv[0] in WASIX subprocesses should resolve to the atom rather than the full command#6516
Arshia001 wants to merge 3 commits intomainfrom
fix/command-exec-atom-name

Conversation

@Arshia001
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings April 24, 2026 15:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates WASIX command execution so that argv[0] in spawned processes resolves to the underlying atom (via a canonical atom VFS path) instead of the command wrapper, preventing command metadata (notably main_args) from being re-applied on re-exec.

Changes:

  • Add a new WASM test that re-execs via argv[0] and asserts main_args are not re-injected.
  • Inject per-command atoms into a dedicated /bin/.__atoms/... path and prefer that path for argv[0]/exec_name.
  • Add BinaryPackageCommand::atom_vfs_path() to compute the canonical atom VFS path.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
lib/wasix/tests/wasm_tests/proc_exec_command_argv0/main.c New C harness that re-execs via argv[0] and validates arg behavior.
lib/wasix/tests/wasm_tests/proc_exec_command_argv0/build.sh Build script for the new WASM test binary.
lib/wasix/tests/wasm_tests/proc_exec_command_argv0.rs New Rust integration test building a package with distinct command/atom names and main_args.
lib/wasix/tests/wasm_tests/mod.rs Registers the new test module.
lib/wasix/src/state/env.rs Injects atoms under /bin/.__atoms/... and prefers the atom VFS path for argv[0].
lib/wasix/src/runners/wasi.rs Prefers atom VFS path for exec name when no explicit annotation exec_name is set.
lib/wasix/src/bin_factory/binary_package.rs Adds atom_vfs_path() helper for canonical atom VFS path derivation.

Comment thread lib/wasix/tests/wasm_tests/proc_exec_command_argv0/main.c Outdated
Comment thread lib/wasix/src/bin_factory/binary_package.rs
Comment thread lib/wasix/src/state/env.rs Outdated
Comment thread lib/wasix/src/state/env.rs Outdated
Comment on lines +1390 to +1395
// Prefer an explicit exec_name from the annotation; otherwise use
// the atom's canonical VFS path (e.g.
// "/bin/.__atoms/wasmer/php/php") so that re-exec via argv[0] finds
// the raw wasm without triggering prepare_spawn again.
let argv0 = exec_name.or_else(|| cmd.atom_vfs_path());
if let Some(argv0) = argv0 {
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

Overwriting argv[0] with cmd.atom_vfs_path() assumes the atom has been injected at that path. If atom injection is best-effort (or can fail), consider falling back to the previous exec_name/command name behavior unless the atom path is known to exist, to avoid breaking programs that re-exec themselves via argv[0].

Suggested change
// Prefer an explicit exec_name from the annotation; otherwise use
// the atom's canonical VFS path (e.g.
// "/bin/.__atoms/wasmer/php/php") so that re-exec via argv[0] finds
// the raw wasm without triggering prepare_spawn again.
let argv0 = exec_name.or_else(|| cmd.atom_vfs_path());
if let Some(argv0) = argv0 {
// Only replace argv[0] when the package explicitly provides an
// exec_name. Falling back to the atom VFS path here is unsafe
// unless injection at that path is known to have succeeded, and a
// missing path can break programs that re-exec themselves via
// argv[0].
if let Some(argv0) = exec_name {

Copilot uses AI. Check for mistakes.
Comment thread lib/wasix/tests/wasm_tests/proc_exec_command_argv0.rs Outdated
Comment thread lib/wasix/tests/wasm_tests/proc_exec_command_argv0.rs
Arshia001 and others added 2 commits April 27, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants