diff --git a/hum/src/main.rs b/hum/src/main.rs index 466dc729..3f19df40 100644 --- a/hum/src/main.rs +++ b/hum/src/main.rs @@ -308,7 +308,7 @@ fn now_ms() -> u64 { } fn probe_thrum(sock: &Path) -> Result<()> { - use std::io::{Read, Write}; + use std::io::Read; use std::os::unix::net::UnixStream; use std::time::Duration; if !sock.exists() { @@ -317,8 +317,6 @@ fn probe_thrum(sock: &Path) -> Result<()> { let mut s = UnixStream::connect(sock) .map_err(|e| anyhow::anyhow!("connect refused ({e}) — stale socket, humd crashed"))?; s.set_read_timeout(Some(Duration::from_secs(1)))?; - s.set_write_timeout(Some(Duration::from_secs(1)))?; - s.write_all(b"{\"chi\":\"hello\",\"sid\":\"hum-doctor-probe\"}\n")?; let mut buf = [0u8; 256]; match s.read(&mut buf) { Ok(0) => anyhow::bail!("socket closed without breath"), diff --git a/humctl/src/main.rs b/humctl/src/main.rs index fe56ba18..342e0972 100644 --- a/humctl/src/main.rs +++ b/humctl/src/main.rs @@ -152,7 +152,7 @@ fn logs(lines: u32) -> Result<()> { fn health() -> Result<()> { let sock = hum_paths::thrum_sock_resolved(); - use std::io::{Read, Write}; + use std::io::Read; use std::os::unix::net::UnixStream; use std::time::Duration; if !sock.exists() { @@ -161,8 +161,6 @@ fn health() -> Result<()> { let mut s = UnixStream::connect(&sock).with_context(|| format!("connect {}", sock.display()))?; s.set_read_timeout(Some(Duration::from_secs(1)))?; - s.set_write_timeout(Some(Duration::from_secs(1)))?; - s.write_all(b"{\"chi\":\"hello\",\"sid\":\"humctl-health\"}\n")?; let mut buf = [0u8; 256]; match s.read(&mut buf) { Ok(0) => bail!("socket closed without breath"), diff --git a/humd/src/lib.rs b/humd/src/lib.rs index ae1df819..db9d67c4 100644 --- a/humd/src/lib.rs +++ b/humd/src/lib.rs @@ -555,17 +555,23 @@ async fn autoupdate_check_once() -> Result { return Ok(false); } info!(local = %stamped, upstream = %upstream_trim, "autoupdate.newer.found"); - let status = tokio::process::Command::new("bash") - .arg("-c") - .arg("curl -fsSL https://raw.githubusercontent.com/adiled/hum/main/install | bash") - .status() - .await?; + let status = installer_outliving_humd( + "curl -fsSL https://raw.githubusercontent.com/adiled/hum/main/install | bash", + ) + .status() + .await?; if !status.success() { anyhow::bail!("installer exited with {status}"); } Ok(true) } +fn installer_outliving_humd(script: &str) -> tokio::process::Command { + let mut cmd = tokio::process::Command::new("bash"); + cmd.arg("-c").arg(script).process_group(0); + cmd +} + fn parse_tag_name(body: &str) -> Option { let needle = "\"tag_name\":"; let start = body.find(needle)? + needle.len(); @@ -2291,3 +2297,21 @@ const BREATH_EVERY: Duration = Duration::from_secs(2); fn parse_humd_id(s: &str) -> Option { ensemble::Hid::from_hex(s).ok() } + +#[cfg(test)] +mod autoupdate_tests { + use super::*; + + #[tokio::test] + async fn the_installer_leads_its_own_process_group_so_a_bootout_of_humd_spares_it() { + let out = installer_outliving_humd("echo $$ $(ps -o pgid= -p $$)") + .output() + .await + .unwrap(); + let said = String::from_utf8(out.stdout).unwrap(); + let mut words = said.split_whitespace(); + let pid = words.next().unwrap(); + let pgid = words.next().unwrap(); + assert_eq!(pid, pgid); + } +}