Skip to content

Conversation

@tallpsmith
Copy link
Contributor

Summary

Fixes #2307 - pmcd now runs in foreground mode when launched by launchctl on macOS, preventing the parent process exit after fork from being interpreted as a crash.

Changes

  • build/mac/io.pcp.pmcd.plist: Added PMCD_LAUNCHED_BY_LAUNCHD environment variable and enabled KeepAlive
  • src/pmcd/rc_pmcd: Detect launchctl environment and add -f flag to run pmcd in foreground mode

Benefits

  • Enables proper launchctl process monitoring and crash recovery
  • Uses existing pmcd foreground mode (-f flag)
  • Platform-specific solution that doesn't affect other platforms
  • Preserves all rc_pmcd setup logic (PMNS rebuild, PMDA setup, etc.)

Test Plan

See test plan below - validation needed on macOS with launchctl.

Run pmcd in foreground mode when launched by launchctl to prevent the
parent process exit after fork from being interpreted as a crash.

- Add PMCD_LAUNCHED_BY_LAUNCHD env var in io.pcp.pmcd.plist
- Enable KeepAlive for proper process monitoring
- Detect env var in rc_pmcd and add -f flag to run in foreground
Adds automated test script and manual testing guide for validating
the launchctl pmcd fork issue fix on macOS systems.

- test-pmcd-launchctl.sh: Comprehensive automated test suite with
  proper timeout handling for slow VMs (3-minute timeouts)
- TESTING.md: Manual testing procedures and troubleshooting guide

Tests validate foreground mode operation, KeepAlive functionality,
and proper launchctl service management.

Placed in build/mac/qa/ to keep macOS-specific tests separate from
the main qa/ suite. Not included in macOS package distribution
(consistent with macOS installer excluding test infrastructure).
@tallpsmith tallpsmith marked this pull request as ready for review December 5, 2025 21:54
@tallpsmith tallpsmith added the macOS For issues specific or related to macOS label Dec 5, 2025
@tallpsmith tallpsmith requested a review from natoscott December 7, 2025 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

macOS For issues specific or related to macOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot detect pmcd crash on macOS - launchctl is unable to detect failure and auto-restart

1 participant