Skip to main content

codex_exec_server/
runtime_paths.rs

1use std::path::PathBuf;
2
3use codex_utils_absolute_path::AbsolutePathBuf;
4
5/// Runtime paths needed by exec-server child processes.
6#[derive(Clone, Debug, Eq, PartialEq)]
7pub struct ExecServerRuntimePaths {
8    /// Stable path to the Codex executable used to launch hidden helper modes.
9    pub codex_self_exe: AbsolutePathBuf,
10    /// Path to the Linux sandbox helper alias used when the platform sandbox
11    /// needs to re-enter Codex by argv0.
12    pub codex_linux_sandbox_exe: Option<AbsolutePathBuf>,
13}
14
15impl ExecServerRuntimePaths {
16    pub fn from_optional_paths(
17        codex_self_exe: Option<PathBuf>,
18        codex_linux_sandbox_exe: Option<PathBuf>,
19    ) -> std::io::Result<Self> {
20        let codex_self_exe = codex_self_exe.ok_or_else(|| {
21            std::io::Error::new(
22                std::io::ErrorKind::InvalidInput,
23                "Codex executable path is not configured",
24            )
25        })?;
26        Self::new(codex_self_exe, codex_linux_sandbox_exe)
27    }
28
29    pub fn new(
30        codex_self_exe: PathBuf,
31        codex_linux_sandbox_exe: Option<PathBuf>,
32    ) -> std::io::Result<Self> {
33        Ok(Self {
34            codex_self_exe: absolute_path(codex_self_exe)?,
35            codex_linux_sandbox_exe: codex_linux_sandbox_exe.map(absolute_path).transpose()?,
36        })
37    }
38}
39
40fn absolute_path(path: PathBuf) -> std::io::Result<AbsolutePathBuf> {
41    AbsolutePathBuf::from_absolute_path(path.as_path())
42        .map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidInput, err))
43}