feat: add spawn_with_child for custom ChildWrapper spawners#34
Open
domenkozar wants to merge 1 commit intowatchexec:mainfrom
Open
feat: add spawn_with_child for custom ChildWrapper spawners#34domenkozar wants to merge 1 commit intowatchexec:mainfrom
domenkozar wants to merge 1 commit intowatchexec:mainfrom
Conversation
Changes `spawn_with` so the closure returns `Box<dyn ChildWrapper>` instead of a raw `Child`. The default `spawn()` wraps the child before calling `spawn_with`. This enables spawning via external mechanisms (e.g. a privileged helper) that provide their own child lifecycle management. The hook pipeline is: pre_spawn, spawner closure, wrap_child. post_spawn is kept on the CommandWrapper trait but no longer called by spawn_inner (it had zero implementations). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
efb7c73 to
795921b
Compare
domenkozar
added a commit
to domenkozar/watchexec
that referenced
this pull request
Mar 14, 2026
Changes `set_spawn_fn` so the closure returns `Box<dyn ChildWrapper>` instead of `tokio::process::Child`. The supervisor calls `CommandWrap::spawn_with()` (updated in process-wrap to accept `Box<dyn ChildWrapper>`) so pre_spawn and wrap_child hooks still run. This allows callers to return custom ChildWrapper implementations (e.g. for processes spawned via a privileged cap-server) where the child is not a standard tokio::process::Child. Depends on: watchexec/process-wrap#34 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
domenkozar
added a commit
to domenkozar/watchexec
that referenced
this pull request
Mar 14, 2026
Changes `set_spawn_fn` so the closure returns `Box<dyn ChildWrapper>` instead of `tokio::process::Child`. The supervisor calls `CommandWrap::spawn_with()` (updated in process-wrap to accept `Box<dyn ChildWrapper>`) so pre_spawn and wrap_child hooks still run. This allows callers to return custom ChildWrapper implementations (e.g. for processes spawned via a privileged cap-server) where the child is not a standard tokio::process::Child. Depends on: watchexec/process-wrap#34 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CommandWrap::spawn_with_child()which accepts a closure returningBox<dyn ChildWrapper>instead of a rawChildpre_spawnandwrap_childhooks still run;post_spawnis skipped (requires a concreteChild)set_spawn_fnto return customChildWrapperimplementationsMotivation
When a process is spawned by an external mechanism (e.g. a privileged cap-server for Linux capability granting), the result is not a
tokio::process::Child. The existingspawn_withrequires returning a concreteChild, making this impossible.spawn_with_childacceptsBox<dyn ChildWrapper>directly while still running the process-wrap hook pipeline.Test plan
cargo check --features tokio1passes🤖 Generated with Claude Code