Skip to main content

soma_self_update/
unix.rs

1use std::ffi::OsString;
2use std::path::Path;
3use std::process::Command;
4
5/// Builds a restart command without consulting global process arguments.
6pub fn restart_command(executable: &Path, args: impl IntoIterator<Item = OsString>) -> Command {
7    let mut command = Command::new(executable);
8    command.args(args);
9    command
10}
11
12/// Replaces the current Unix process with the installed executable.
13///
14/// Adopters supervised by systemd or another process manager may instead exit
15/// with an agreed restart status after receiving either `InstallOutcome` variant.
16#[cfg(unix)]
17pub fn reexec(
18    executable: &Path,
19    args: impl IntoIterator<Item = OsString>,
20) -> crate::Result<std::convert::Infallible> {
21    use std::os::unix::process::CommandExt;
22
23    let error = restart_command(executable, args).exec();
24    Err(crate::UpdateError::io(executable, error))
25}