{"record":{"id":"437f4f077b24913d","repo":"shadowsocks/shadowsocks-rust","slug":"cannot-get-current-working-directory-err","errorCode":null,"errorMessage":"cannot get current working directory, {err:?}","messagePattern":"cannot get current working directory, (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/daemonize/unix.rs","lineNumber":12,"sourceCode":"use std::{env::current_dir, path::Path};\n\nuse super::daemonize::Daemonize;\nuse log::error;\n\n/// Daemonize a server process in a *nix standard way\n///\n/// This function will redirect `stdout`, `stderr` to `/dev/null`,\n/// and follow the exact behavior in shadowsocks-libev\npub fn daemonize<F: AsRef<Path>>(pid_path: Option<F>) {\n    let pwd = current_dir()\n        .unwrap_or_else(|err| panic!(\"cannot get current working directory, {err:?}\"))\n        .canonicalize()\n        .unwrap_or_else(|err| panic!(\"cannot get absolute path to working directory, {err:?}\"));\n    let mut d = Daemonize::new().umask(0).working_directory(pwd);\n\n    if let Some(p) = pid_path {\n        d = d.pid_file(p);\n    }\n\n    if let Err(err) = d.start() {\n        error!(\"failed to daemonize, {:?} ({})\", err, err);\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/src/daemonize/unix.rs#L1-L25","documentation":"The `daemonize` helper reads std::env::current_dir() and panics if it fails. Daemonizing with the Daemonize crate requires a known working directory, and shadowsocks follows shadowsocks-libev's behavior of never daemonizing with an unknown cwd. The panic is fail-fast at startup for the `-d`/daemon mode only.","triggerScenarios":"Calling the public `daemonize(pid_path)` in src/daemonize/unix.rs when `current_dir()` returns an error — typically because the process's current directory was deleted while the process was running, or it cannot be accessed.","commonSituations":"Starting the server from a directory that is later removed before daemonizing; running from a deleted tmpfs path in scripts; a wrapper script that cd's into a transient directory and then execs the binary.","solutions":["Run the binary from a directory that still exists (e.g. cd / before starting)","Re-create the deleted working directory or restart the process from a valid path","Avoid daemon mode (-d) and manage the process with systemd instead","Check filesystem health if paths vanish unexpectedly"],"exampleFix":"// before\nshadowsocks-local -c config.json -d\n# (launched from a deleted directory)\n// after\ncd / && shadowsocks-local -c /etc/shadowsocks/config.json -d","handlingStrategy":"validation","validationCode":"# ensure cwd exists before daemonizing:\ncd / || exit 1; shadowsocks-server -c config.json -d","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always `cd /` (or a stable dir) before starting daemon mode","Avoid launching daemons from temp/deleted paths","Prefer systemd over -d for production daemonization","Restart the process if its cwd was removed"],"tags":["panic","daemonize","unix","filesystem"],"backgroundTag":"directory-not-found","analyzedSha":"8eb0f0a65b1d976ab6bed5787327ef86529b0435","analyzedAt":"2026-09-09T12:20:43.168Z","contentChangedAt":"2026-09-09T12:20:43.168Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}