Skip to content

examples/paseo: the preflight daemon guard silently no-ops without lsof #2

Description

@camerontaylor

Companion to #1 — same shape, different file: a guard that fails open instead of loud.

examples/paseo/desvio.conf:31 resolves the running daemon's cwd with lsof:

cwd=$(lsof -a -p "$pid" -d cwd -Fn 2>/dev/null | sed -n 's/^n//p' | head -1)
case "${cwd:-}" in
  "$DESVIO_WORKTREE"|"$DESVIO_WORKTREE"/*) die "a daemon (pid $pid) is serving from this tree: ..." ;;
esac

lsof is not installed by default on Arch (and is absent from most minimal images). When it is missing, cwd is empty, ${cwd:-} matches no branch, and desvio_preflight returns 0 — so the guard that is supposed to refuse to build under a live daemon quietly permits it. The README is explicit about why that guard exists:

One worktree. Anything that reads the tree while desvio rewrites it will misbehave; that is what desvio_preflight is for.

The failure mode is the bad one: a rebuild rewrites dist/ under a daemon that lazily requires from it, and nothing warned.

Same dependency in examples/paseo/start.sh:79,162 and install.sh:86-88, where a missing lsof degrades the "who holds 6767" and "which tree is it serving" reporting rather than a safety check.

Suggestion

/proc/<pid>/cwd is exact, needs no extra process, and is not subject to lsof's permission quirks. Keeping the lsof branch preserves macOS:

if [ -r "/proc/$pid/cwd" ]; then
  cwd=$(readlink "/proc/$pid/cwd" 2>/dev/null)
else
  cwd=$(lsof -a -p "$pid" -d cwd -Fn 2>/dev/null | sed -n 's/^n//p' | head -1)
fi

Running that locally and it works fine. For the port-holder lookup in install.sh, ss -lptnH "sport = :6767" is the usual Linux equivalent.

Happy to send a PR across the three files if you want it — held off because the approach is a judgement call about your example, and install.sh/start.sh use lsof for reporting rather than for a guard, so they may deserve different treatment.

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions