Write a PID file for a background forward. File format: ` \t \t `
(
name: &str,
port: u16,
pid: u32,
sandbox_id: &str,
bind_addr: &str,
)
| 30 | /// |
| 31 | /// File format: `<pid>\t<sandbox_id>\t<bind_addr>` |
| 32 | pub fn write_forward_pid( |
| 33 | name: &str, |
| 34 | port: u16, |
| 35 | pid: u32, |
| 36 | sandbox_id: &str, |
| 37 | bind_addr: &str, |
| 38 | ) -> Result<()> { |
| 39 | let dir = forward_pid_dir()?; |
| 40 | create_dir_restricted(&dir)?; |
| 41 | let path = forward_pid_path(name, port)?; |
| 42 | std::fs::write(&path, format!("{pid}\t{sandbox_id}\t{bind_addr}")) |
| 43 | .into_diagnostic() |
| 44 | .wrap_err("failed to write forward PID file")?; |
| 45 | Ok(()) |
| 46 | } |
| 47 | |
| 48 | /// Find the PID of a backgrounded SSH forward by searching for the matching |
| 49 | /// SSH process. Falls back to `pgrep` since SSH `-f` forks a new process |
no test coverage detected