roc-lang / roc-lang/basic-cli

Env.exePath returns "/memfd:roc_file_descriptor (deleted)" when running as script

Open
#265 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

blocked
Dominant language
Rust
Stars
121
Forks
45
Avg merge
18h 43m
Merged PRs (30d)
10

Description

Minimal Reproducible Example:

app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.16.0/O00IPk-Krg_diNS2dVWlI0ZQP794Vctxzv0ha96mK0E.tar.br",
}

import pf.Env
import pf.Path

main = 
    exePath = Env.exePath!
    exePathStr = Path.display exePath
    dbg exePathStr
    Task.ok {}

Run as roc test.roc

Expected Behavior:

Output of /home/user/path/to/script/test.roc

Actual Behavior:

Output of /memfd:roc_file_descriptor (deleted)

Environment:

OS: Archlinux
Roc Version: roc nightly pre-release, built from commit 06996d8

Context

Discussed in https://roc.zulipchat.com/#narrow/channel/231634-beginners/topic/basic-cli.20debugging.20Env.2EexePath

Implementation (https://github.com/roc-lang/basic-cli/blob/918c1dcd2a863ea336e9fa0e70fa548f7107b6f0/crates/roc_host/src/lib.rs#L432) just defers to Rust's std::env::current_exe() (https://github.com/rust-lang/rust/blob/a8e75c53d0036b5d012cbc0ee5de17f8991fe60c/library/std/src/sys/pal/unix/os.rs#L406) which reads /proc/self/exe which seems to be invalid when running through roc <file>.

Somewhat related is https://github.com/roc-lang/roc/pull/7172 which fixed argv[0] to be set correctly.

Proposed solution is to use argv[0] and ideally combine with Env.cwd for a full absolute path (similar to https://github.com/rust-lang/rust/blob/a8e75c53d0036b5d012cbc0ee5de17f8991fe60c/library/std/src/sys/pal/unix/os.rs#L253) if /proc/self/exe can't be utilized.

Credit to @jwoudenberg and @lukewilliamboswell who did most of the work of putting this information together.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided roc test.roc example, then read crates/roc_host/src/lib.rs around line 432 and the linked Rust current_exe() implementation. Compare the available argv[0] and Env.cwd context, and verify that Env.exePath reports the script's absolute path instead of the memfd path.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.