Refuse non-replace pidfile.

If the given pid file already exists, but --replace is not given,
refuse to start the server.
This commit is contained in:
Rasmus Kaj 2017-08-31 20:09:20 +02:00
parent ec52f0b57e
commit 97076336a6

View File

@ -1,6 +1,7 @@
use libc::{SIGHUP, getpid, kill, pid_t};
use std::fs::File;
use std::io::{ErrorKind, Read, Write};
use std::path::Path;
pub fn handle_pid_file(pidfile: &str, replace: bool) -> Result<(), String> {
if replace {
@ -8,6 +9,10 @@ pub fn handle_pid_file(pidfile: &str, replace: bool) -> Result<(), String> {
info!("Killing old pid {}.", oldpid);
unsafe { kill(oldpid, SIGHUP); }
}
} else {
if Path::new(pidfile).exists() {
return Err(format!("Pid file {:?} exists.", pidfile))
}
}
let pid = unsafe { getpid() };
debug!("Should write pid {} to {}", pid, pidfile);