From 39b3821cd5c7bf10471c20d17522761f06a7d814 Mon Sep 17 00:00:00 2001 From: code-yeongyu Date: Thu, 6 Aug 2026 19:03:27 +0900 Subject: [PATCH] scratch: fix probe to avoid unsafe --- rust/crates/runtime/tests/probe_unshare.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/rust/crates/runtime/tests/probe_unshare.rs b/rust/crates/runtime/tests/probe_unshare.rs index d4328207..072aceb0 100644 --- a/rust/crates/runtime/tests/probe_unshare.rs +++ b/rust/crates/runtime/tests/probe_unshare.rs @@ -1,4 +1,4 @@ -//! Scratch probe: dump GitHub runner unshare semantics (temporary, PR will be closed). +//! Scratch probe: dump GitHub runner unshare semantics (temporary, PRs will be closed). #![cfg(target_os = "linux")] use std::process::Command; @@ -15,11 +15,18 @@ fn run(args: &[&str]) -> (i32, String, String) { } } +fn sh(cmd: &str) -> String { + Command::new("sh") + .args(["-lc", cmd]) + .output() + .map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string()) + .unwrap_or_default() +} + #[test] fn dump_unshare_semantics() { - let uid = unsafe { libc::getuid() }; let mut report = String::new(); - report.push_str(&format!("uid={uid} euid={}\n", unsafe { libc::geteuid() })); + report.push_str(&format!("uid line: {}\n", sh("id"))); for f in ["/etc/subuid", "/etc/subgid"] { report.push_str(&format!("--- {f} ---\n")); if let Ok(s) = std::fs::read_to_string(f) { @@ -42,6 +49,10 @@ fn dump_unshare_semantics() { "auto-full", &["--user", "--map-root-user", "--map-auto", "--mount", "--ipc", "--pid", "--uts", "--fork", "sh", "-lc", "echo alpha"][..], ), + ( + "auto-full-echo-multi", + &["--user", "--map-root-user", "--map-auto", "--mount", "--ipc", "--pid", "--uts", "--fork", "sh", "-lc", "echo alpha from bash"][..], + ), ] { let (rc, so, se) = run(args); report.push_str(&format!("[{name}] rc={rc} stdout={so:?} stderr={se:?}\n"));