feat: write pid in addition to port to server info (#4571)
This is nice to have for debugging. While here, also cleaned up a bunch of unnecessary noise in `write_server_info()`.
This commit is contained in:
@@ -49,6 +49,7 @@ pub struct Args {
|
|||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct ServerInfo {
|
struct ServerInfo {
|
||||||
port: u16,
|
port: u16,
|
||||||
|
pid: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Entry point for the library main, for parity with other crates.
|
/// Entry point for the library main, for parity with other crates.
|
||||||
@@ -100,15 +101,17 @@ fn write_server_info(path: &Path, port: u16) -> Result<()> {
|
|||||||
if let Some(parent) = path.parent()
|
if let Some(parent) = path.parent()
|
||||||
&& !parent.as_os_str().is_empty()
|
&& !parent.as_os_str().is_empty()
|
||||||
{
|
{
|
||||||
let parent_display = parent.display();
|
fs::create_dir_all(parent)?;
|
||||||
fs::create_dir_all(parent).with_context(|| format!("create_dir_all {parent_display}"))?;
|
|
||||||
}
|
}
|
||||||
let info = ServerInfo { port };
|
|
||||||
let data = serde_json::to_vec(&info).context("serialize startup info")?;
|
let info = ServerInfo {
|
||||||
let p = path.display();
|
port,
|
||||||
let mut f = File::create(path).with_context(|| format!("create {p}"))?;
|
pid: std::process::id(),
|
||||||
f.write_all(&data).with_context(|| format!("write {p}"))?;
|
};
|
||||||
f.write_all(b"\n").with_context(|| format!("newline {p}"))?;
|
let mut data = serde_json::to_string(&info)?;
|
||||||
|
data.push('\n');
|
||||||
|
let mut f = File::create(path)?;
|
||||||
|
f.write_all(data.as_bytes())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user