diff --git a/src/config/jailer.rs b/src/config/jailer.rs index 4f2c5e6..f536950 100644 --- a/src/config/jailer.rs +++ b/src/config/jailer.rs @@ -15,7 +15,7 @@ pub struct Jailer<'j> { jailer_binary: Cow<'j, Path>, chroot_base_dir: Cow<'j, Path>, workspace_dir: Cow<'j, Path>, - pub(crate) mode: JailerMode, + pub(crate) mode: JailerMode<'j>, // TODO: We need an equivalent of ChrootStrategy. } @@ -64,7 +64,7 @@ impl<'j> Jailer<'j> { /// The mode of the jailer process. #[derive(Derivative)] #[derivative(Debug, Default)] -pub enum JailerMode { +pub enum JailerMode<'j> { /// The jailer child process will run attached to the parent process. #[derivative(Default)] Attached(Stdio), @@ -72,8 +72,9 @@ pub enum JailerMode { Daemon, /// Launch the jailer in a tmux session. /// - /// The tmux session will be named `` and tmux will be launched in detached mode. - Tmux, + /// If the session name is not provided, `` is used as the session name. tmux will be + /// launched in detached mode. + Tmux(Option>), } /// The standard IO handlers. @@ -170,7 +171,7 @@ impl<'j> JailerBuilder<'j> { } /// The mode of the jailer process. - pub fn mode(mut self, mode: JailerMode) -> Self { + pub fn mode(mut self, mode: JailerMode<'j>) -> Self { self.jailer.mode = mode; self } diff --git a/src/machine.rs b/src/machine.rs index b32ac74..1d21338 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -162,13 +162,16 @@ impl<'m> Machine<'m> { stdio.stdout.take().unwrap_or_else(Stdio::inherit), stdio.stderr.take().unwrap_or_else(Stdio::inherit), ), - JailerMode::Tmux => { + JailerMode::Tmux(session_name) => { + let session_name = session_name + .clone() + .unwrap_or_else(|| vm_id.to_string().into()); let mut cmd = Command::new("tmux"); cmd.args(&[ "new-session", "-d", "-s", - &vm_id.to_string(), + &session_name, jailer.jailer_binary().to_str().unwrap(), ]); @@ -286,10 +289,13 @@ impl<'m> Machine<'m> { } trace!("{vm_id}: Successfully sent KILL signal to VM (pid: `{pid}`)."); } - JailerMode::Tmux => { + JailerMode::Tmux(session_name) => { + let session_name = session_name + .clone() + .unwrap_or_else(|| vm_id.to_string().into()); // In case of tmux, we need to kill the tmux session. let cmd = &mut Command::new("tmux"); - cmd.args(&["kill-session", "-t", &vm_id.to_string()]); + cmd.args(&["kill-session", "-t", &session_name]); trace!("{vm_id}: Running command: {:?}", cmd); cmd.spawn()?.wait().await?; }