bxcore, loopd, inferproxy: a lock file keeps each to one instance
Co-Authored-By: ornith-1.5-35b-a3b <agent@wntrmute.dev>
This commit is contained in:
@@ -4,6 +4,7 @@ use std::os::unix::fs::PermissionsExt;
|
||||
use std::path::PathBuf;
|
||||
use std::process;
|
||||
|
||||
use bxcore::instance;
|
||||
use inferproxy::{Limits, serve};
|
||||
|
||||
fn main() {
|
||||
@@ -39,6 +40,19 @@ fn main() {
|
||||
};
|
||||
|
||||
let path: PathBuf = listen.into();
|
||||
// One inferproxy per socket (M5b spec, section 9a): the lock beside the socket comes before
|
||||
// the stale socket is removed, so a second copy never takes the socket of the one that runs.
|
||||
// Held until the process ends; `process::exit` leaves it to the system to release.
|
||||
let mut lock_path = path.clone().into_os_string();
|
||||
lock_path.push(".lock");
|
||||
let lock_path = PathBuf::from(lock_path);
|
||||
let _instance = match instance::lock(&lock_path) {
|
||||
Ok(held) => held,
|
||||
Err(e) => {
|
||||
eprintln!("{}", e.line("inferproxy", &lock_path));
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
match fs::remove_file(&path) {
|
||||
Ok(()) => {}
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
|
||||
|
||||
Reference in New Issue
Block a user