From cba7fa4c3bd8d81d12bb1baeb5fd9fc034c54f73 Mon Sep 17 00:00:00 2001 From: spyophobia <76800505+spyophobia@users.noreply.github.com> Date: Fri, 8 Oct 2021 03:38:08 +0800 Subject: [PATCH] daemon starts in pwd (#640) This is the default behavior when not daemonizing. --- bin/common/daemonize/unix.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/common/daemonize/unix.rs b/bin/common/daemonize/unix.rs index 9f36bd9661c5..70f9f64b1c78 100644 --- a/bin/common/daemonize/unix.rs +++ b/bin/common/daemonize/unix.rs @@ -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>(pid_path: Option) { - 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); }