diff options
Diffstat (limited to 'pkgs')
| -rw-r--r-- | pkgs/populate/src/run.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/pkgs/populate/src/run.rs b/pkgs/populate/src/run.rs index cf6364d..c4be18c 100644 --- a/pkgs/populate/src/run.rs +++ b/pkgs/populate/src/run.rs @@ -189,7 +189,7 @@ impl Context { options.extend(["-p".to_string(), port.clone()]); } if shared { - let control_path = format!("ControlPath={}/ssh-%r@%h:%p.sock", self.tmpdir.display()); + let control_path = control_path(&self.tmpdir); // The keepalives end the connection, and with it the command // holding the lock on the target, about a minute after the // target stops answering, e.g. when the network fails, instead @@ -482,6 +482,18 @@ pub fn local_shell(script: &str, args: &[&str], dir: &Path) -> Command { command } +/// The ssh option naming the master connection's socket in tmpdir. The +/// name is short, since the socket's path, with the suffix ssh adds while +/// it sets up the connection, must fit in about 100 bytes, and TMPDIR can +/// be long, e.g. nix-shell's below /run/user; a run has only one target. +/// ssh expands % in ControlPath, so the directory's ones get doubled. +fn control_path(tmpdir: &Path) -> String { + format!( + "ControlPath={}/ssh.sock", + tmpdir.to_string_lossy().replace('%', "%%") + ) +} + /// The program named name in PATH. fn which(name: &str) -> Option<PathBuf> { let path = std::env::var_os("PATH")?; @@ -645,6 +657,18 @@ mod tests { assert_eq!(quote("it's"), r"'it'\''s'"); } + #[test] + fn control_paths() { + assert_eq!( + control_path(Path::new("/tmp/populate.abc")), + "ControlPath=/tmp/populate.abc/ssh.sock" + ); + assert_eq!( + control_path(Path::new("/tmp/50%/populate.abc")), + "ControlPath=/tmp/50%%/populate.abc/ssh.sock" + ); + } + fn target(user: Option<&str>, host: &str) -> Target { Target { user: user.map(str::to_string), |
