shadowsocks/shadowsocks-rust · error

cannot get absolute path to working directory, {err:?}

Error message

cannot get absolute path to working directory, {err:?}

What it means

After fetching the current directory, `daemonize` calls `.canonicalize()` to obtain the absolute path and panics if that fails. Canonicalization fails if the path does not exist, is a broken symlink chain, or the process lacks permission to traverse a component. Like the previous error, it is a fail-fast startup guard for daemon mode.

Source

Thrown at src/daemonize/unix.rs:14

use std::{env::current_dir, path::Path};

use super::daemonize::Daemonize;
use log::error;

/// Daemonize a server process in a *nix standard way
///
/// 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 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);
    }

    if let Err(err) = d.start() {
        error!("failed to daemonize, {:?} ({})", err, err);
    }
}

View on GitHub (pinned to 8eb0f0a65b)

Solutions

  1. Start the server from a stable, existing directory (cd /tmp or / first)
  2. Remove or fix broken symlinks in the working directory path
  3. Ensure the process user can traverse all path components of the cwd
  4. Skip daemon mode and use a service manager (systemd) with its own WorkingDirectory

Example fix

// before
ExecStart=/usr/bin/shadowsocks-local -c /etc/ss/config.json -d
WorkingDirectory=/opt/deleted-dir
// after
ExecStart=/usr/bin/shadowsocks-local -c /etc/ss/config.json -d
WorkingDirectory=/var/lib/shadowsocks
Defensive patterns

Strategy: validation

Validate before calling

let pwd = std::env::current_dir()?.canonicalize()?; // precheck before calling daemonize()

Prevention

When it happens

Trigger: Calling public `daemonize(pid_path)` when `current_dir().canonicalize()` returns Err — the cwd path contains a broken symlink, was unmounted, or traversal permission is denied at startup time.

Common situations: Running from a symlinked directory whose target was deleted; cwd on an unmounted/removable filesystem; restricted permissions on a parent directory when starting the daemon.

Related errors


AI-assisted analysis of shadowsocks/shadowsocks-rust@8eb0f0a65b (2026-09-09). Data as JSON: /api/errors/23c3338fd6313141. Report an issue: GitHub.