Skip to content

Commit

Permalink
daemon starts in pwd (#640)
Browse files Browse the repository at this point in the history
This is the default behavior when not daemonizing.
  • Loading branch information
spyophobia authored and zonyitoo committed Oct 7, 2021
1 parent 9641023 commit cba7fa4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions bin/common/daemonize/unix.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::Path;
use std::{env::current_dir, path::Path};

use daemonize::Daemonize;
use log::error;
Expand All @@ -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);
}
Expand Down

0 comments on commit cba7fa4

Please sign in to comment.