aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-26 20:25:55 +0000
committertv <tv@krebsco.de>2026-11-26 20:25:55 +0000
commitecc5461d8a1147d2da70ea6913333e4d769a2bd2 (patch)
tree4fb84e1963e15058b828d1aab5a971dc257c13bb
parent4daacdbad12cf333da0f1783def2364935672752 (diff)
populate: a short name for the master connection's socket
The socket's path, with the suffix ssh adds while it sets up the master connection, must fit in about 100 bytes. Named after the user, host, and port in a TMPDIR as long as nix-shell's, below /run/user, it didn't: "unix_listener: path ... too long for Unix domain socket". A run has only one target, so the socket is ssh.sock in populate's temporary directory. ssh expands % in ControlPath, so the directory's ones get doubled.
-rw-r--r--pkgs/populate/src/run.rs26
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),