mirror of
https://github.com/openai/codex.git
synced 2026-10-21 17:48:44 +00:00
## What changed Extract the inline test modules for `bundled_bwrap`, `bwrap`, `exec_util`, `launcher`, `proxy_routing`, and `seccomp` into sibling `*_tests.rs` files. Keep them wired through `#[cfg(test)]` and explicit `#[path]` attributes, with existing test coverage and runtime behavior unchanged. GitOrigin-RevId: 79b70a092a19b10716939744542415bc1dcaf0b2
45 lines
1.3 KiB
Rust
45 lines
1.3 KiB
Rust
use std::ffi::CString;
|
|
use std::fs::File;
|
|
use std::os::fd::AsRawFd;
|
|
|
|
pub(crate) fn argv_to_cstrings(argv: &[String]) -> Vec<CString> {
|
|
let mut cstrings: Vec<CString> = Vec::with_capacity(argv.len());
|
|
for arg in argv {
|
|
match CString::new(arg.as_str()) {
|
|
Ok(value) => cstrings.push(value),
|
|
Err(err) => panic!("failed to convert argv to CString: {err}"),
|
|
}
|
|
}
|
|
cstrings
|
|
}
|
|
|
|
pub(crate) fn make_files_inheritable(files: &[File]) {
|
|
for file in files {
|
|
clear_cloexec(file.as_raw_fd());
|
|
}
|
|
}
|
|
|
|
fn clear_cloexec(fd: libc::c_int) {
|
|
// SAFETY: `fd` is an owned descriptor kept alive by `files`.
|
|
let flags = unsafe { libc::fcntl(fd, libc::F_GETFD) };
|
|
if flags < 0 {
|
|
let err = std::io::Error::last_os_error();
|
|
panic!("failed to read fd flags for preserved bubblewrap file descriptor {fd}: {err}");
|
|
}
|
|
let cleared_flags = flags & !libc::FD_CLOEXEC;
|
|
if cleared_flags == flags {
|
|
return;
|
|
}
|
|
|
|
// SAFETY: `fd` is valid and we are only clearing FD_CLOEXEC.
|
|
let result = unsafe { libc::fcntl(fd, libc::F_SETFD, cleared_flags) };
|
|
if result < 0 {
|
|
let err = std::io::Error::last_os_error();
|
|
panic!("failed to clear CLOEXEC for preserved bubblewrap file descriptor {fd}: {err}");
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "exec_util_tests.rs"]
|
|
mod tests;
|