MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / exec_replace

Function exec_replace

crates/update/src/proxy.rs:90–116  ·  view source on GitHub ↗

implementation based on and docs taken verbatim from `cargo_util::ProcessBuilder::exec_replace` Replaces the current process with the target process. On Unix, this executes the process using the Unix syscall `execvp`, which will block this process, and will only return if there is an error. On Windows this isn't technically possible. Instead we emulate it to the best of our ability. One aspect

(cmd: &mut Command)

Source from the content-addressed store, hash-verified

88/// pretty quickly, and if the child handles the signal then we won't terminate
89/// (and we shouldn't!) until the process itself later exits.
90fn exec_replace(cmd: &mut Command) -> io::Result<ExitCode> {
91 #[cfg(unix)]
92 {
93 use std::os::unix::process::CommandExt;
94 // if exec() succeeds, it diverges, so the function just returns an io::Error
95 let err = cmd.exec();
96 Err(err)
97 }
98 #[cfg(windows)]
99 {
100 use windows_sys::Win32::Foundation::{BOOL, FALSE, TRUE};
101 use windows_sys::Win32::System::Console::SetConsoleCtrlHandler;
102
103 unsafe extern "system" fn ctrlc_handler(_: u32) -> BOOL {
104 // Do nothing. Let the child process handle it.
105 TRUE
106 }
107 unsafe {
108 if SetConsoleCtrlHandler(Some(ctrlc_handler), TRUE) == FALSE {
109 return Err(io::Error::other("Unable to set console handler"));
110 }
111 }
112
113 cmd.status()
114 .map(|status| ExitCode::from(status.code().unwrap_or(1).try_into().unwrap_or(1)))
115 }
116}
117
118/// Checks to see if we're running from a subdirectory of a `target` dir that has a `Cargo.toml`
119/// as a sibling, and returns the containing directory of the current executable if so.

Callers 1

run_cliFunction · 0.70

Calls 8

otherFunction · 0.85
statusMethod · 0.80
unwrap_orMethod · 0.80
try_intoMethod · 0.80
codeMethod · 0.80
execMethod · 0.65
ErrFunction · 0.50
mapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…