-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Labels
C-bugCategory: bugCategory: bugS-needs-team-inputStatus: Needs input from team on whether/how to proceed.Status: Needs input from team on whether/how to proceed.Z-scriptNightly: cargo scriptNightly: cargo script
Description
When the script file is created through memfd_create, cargo panics when trying to run the script.
Repro:
use std::os::fd::FromRawFd;
use std::io::Write;
use std::os::unix::process::CommandExt;
unsafe extern "C" {
fn memfd_create(name: *const std::ffi::c_char, flags: std::ffi::c_uint) -> std::ffi::c_int;
}
fn main() {
let fd = unsafe { memfd_create(c"otkeep-script".as_ptr(), 0) };
if fd == -1 {
panic!("memfd_create failed when trying to create script file");
}
let mut f = unsafe { std::fs::File::from_raw_fd(fd) };
f.write_all(SCRIPT.as_bytes()).unwrap();
f.flush().unwrap();
dbg!(std::process::Command::new(format!("/proc/self/fd/{fd}")).exec());
}
const SCRIPT: &str = r#"#!/usr/bin/env -S cargo +nightly -Zscript
fn main() {
println!("Hello World");
}
"#;
Cargo output (as of 1.92.0-nightly (81c3f77a4 2025-10-10)
):
thread 'main' (26272) panicked at src/tools/cargo/src/cargo/core/workspace.rs:454:18:
template is correct: No such file or directory (os error 2)
My use case is that I'm running cargo scripts through my script runner called OtKeep, which stores scripts in a database and uses memfd_create to create temporary files when executing the scripts.
This used to work, but doesn't anymore. The regression seems to be caused by #16073.
Metadata
Metadata
Assignees
Labels
C-bugCategory: bugCategory: bugS-needs-team-inputStatus: Needs input from team on whether/how to proceed.Status: Needs input from team on whether/how to proceed.Z-scriptNightly: cargo scriptNightly: cargo script