mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-11-06 16:14:11 +00:00
daemon starts in pwd (#640)
This is the default behavior when not daemonizing.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::path::Path;
|
||||
use std::{env::current_dir, path::Path};
|
||||
|
||||
use daemonize::Daemonize;
|
||||
use log::error;
|
||||
@@ -8,7 +8,12 @@ use log::error;
|
||||
/// This function will redirect `stdout`, `stderr` to `/dev/null`,
|
||||
/// and follow the exact behavior in shadowsocks-libev
|
||||
pub fn daemonize<F: AsRef<Path>>(pid_path: Option<F>) {
|
||||
let mut d = Daemonize::new().umask(0).chroot("/");
|
||||
let pwd = current_dir()
|
||||
.unwrap_or_else(|err| panic!("cannot get current working directory, {:?}", err))
|
||||
.canonicalize()
|
||||
.unwrap_or_else(|err| panic!("cannot get absolute path to working directory, {:?}", err));
|
||||
let mut d = Daemonize::new().umask(0).working_directory(pwd);
|
||||
|
||||
if let Some(p) = pid_path {
|
||||
d = d.pid_file(p);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user