flox icon indicating copy to clipboard operation
flox copied to clipboard

feat: one watchdog waits for all pids

Open zmitchell opened this issue 1 year ago • 0 comments

Proposed Changes

feat(watchdog): bail if other watchdog exists

Check the registry contents at startup to determine whether another watchdog exists. If another watchdog exists, then we don't need this one and it can terminate. We determine that another watchdog exists if the registry has an entry for this environment and that entry contains activation PIDs.

feat(watchdog): don't check parent on startup

Since we're moving to a single watchdog per activation, the watchdog that's monitoring the activation needs to monitor all of the PIDs that are attached to this activation, not just the PID of the watchdog's parent.

feat(watchdog): wait for all pids on macos

This adds a trait for a generic "watcher" that waits for a termination condition. This commit implements it for a watcher on macOS that terminates once all of the PIDs that it's watching have terminated.

Initialization of kqueue doesn't happen until the Watcher::wait_for_termination method is called, which requires the inner kqueue watcher to be stored as an Option that's later checked at runtime. I think it's impossible for this to ever end up as None after calling wait_for_termination, but a follow up PR could make initialization happen in two stages so that the Option isn't necessary.

feat(watchdog): wait for all pids on linux

This follows the same pattern as the last commit, except we can reuse the guts of the ProcfsWatcher.

Release Notes

N/A

zmitchell avatar Oct 04 '24 00:10 zmitchell