Skip to content

feat: implement --detach daemon daemonization (Unix) - #2487

Merged
oferchen merged 1 commit into
masterfrom
feat/daemon-detach
Feb 23, 2026
Merged

oferchen merged 1 commit into
masterfrom
feat/daemon-detach

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Implement proper daemon process detachment matching upstream rsync's become_daemon() from clientserver.c:1463
  • On Unix: fork, setsid(), redirect stdin/stdout/stderr to /dev/null
  • --detach: fork and run in background (default on Unix)
  • --no-detach: stay in foreground (for systemd, testing, debugging)
  • Daemonization runs after listener bind so startup errors reach stderr
  • PID file records the child's PID (created after fork)
  • Unix-only with #[cfg(unix)] gates; Windows defaults to foreground

Test plan

  • cargo clippy -p daemon --all-targets --all-features --no-deps clean
  • cargo nextest run -p daemon --all-features — 903 tests pass
  • Manual: oc-rsyncd --port 8730 --module test=/tmp/test detaches and writes PID file
  • Manual: oc-rsyncd --no-detach --port 8730 --module test=/tmp/test stays in foreground

Add proper daemon process detachment matching upstream rsync's
become_daemon() from clientserver.c:1463. On Unix, the daemon now
forks, calls setsid() to create a new session, and redirects
stdin/stdout/stderr to /dev/null. The parent exits immediately
while the child continues as a background daemon.

- --detach: fork and run in background (default on Unix)
- --no-detach: stay in foreground (for systemd, testing, debugging)
- Daemonization runs after listener bind so startup errors reach stderr
- PID file records the child's PID (created after fork)
@github-actions github-actions Bot added the enhancement New feature or request label Feb 23, 2026
@oferchen
oferchen merged commit 0815ace into master Feb 23, 2026
31 checks passed
@oferchen
oferchen deleted the feat/daemon-detach branch February 23, 2026 07:24
oferchen added a commit that referenced this pull request May 1, 2026
Add proper daemon process detachment matching upstream rsync's
become_daemon() from clientserver.c:1463. On Unix, the daemon now
forks, calls setsid() to create a new session, and redirects
stdin/stdout/stderr to /dev/null. The parent exits immediately
while the child continues as a background daemon.

- --detach: fork and run in background (default on Unix)
- --no-detach: stay in foreground (for systemd, testing, debugging)
- Daemonization runs after listener bind so startup errors reach stderr
- PID file records the child's PID (created after fork)
oferchen added a commit that referenced this pull request May 5, 2026
Add proper daemon process detachment matching upstream rsync's
become_daemon() from clientserver.c:1463. On Unix, the daemon now
forks, calls setsid() to create a new session, and redirects
stdin/stdout/stderr to /dev/null. The parent exits immediately
while the child continues as a background daemon.

- --detach: fork and run in background (default on Unix)
- --no-detach: stay in foreground (for systemd, testing, debugging)
- Daemonization runs after listener bind so startup errors reach stderr
- PID file records the child's PID (created after fork)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant