Skip to content

Block signal masks pre-fork and restore post-fork. #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 1, 2025

Conversation

iCharlesHu
Copy link
Contributor

This PR introduces proper signal blocking and restoring for custom fork/exec on Linux.

Resolves: iCharlesHu/Subprocess#45
Resolves: iCharlesHu/Subprocess#46

During testing, one of the newly added tests revealed that we were not managing DispatchIO correctly during early terminations on Darwin and Linux. Currently, we simply close the file descriptors in the clean-up handler, which is incorrect because DispatchIO is used for read/write operations on these file descriptors. Modifying the file descriptor after it has been “transferred” to DispatchIO is considered a programmer error.

Rearchitect TrackedFileDescriptor (now renamed DiskIO) to either hold a FileDescriptor or a DispatchIO. We create DispatchIO as the final step of spawn() and use it for read/write operations and cleanup, instead of using a raw file descriptor. This allows DispatchIO to naturally close the file descriptor itself.

@iCharlesHu iCharlesHu requested a review from parkera April 28, 2025 23:41
@iCharlesHu
Copy link
Contributor Author

@swift-ci please test

@iCharlesHu
Copy link
Contributor Author

Instead of a monolithic DiskIO, split CreatedPipe to InputPipe and OutputPipe so we don't have to rely on guard and fatalError() at runtime to guard against scenarios that shouldn't happen.

@iCharlesHu
Copy link
Contributor Author

@swift-ci please test

@iCharlesHu iCharlesHu force-pushed the charles/fork-exec-signals branch from 75505ba to a56ee26 Compare April 29, 2025 21:28
On Darwin and Linux, rearchitect `TrackedFileDescriptor` (now named `DiskIO`) to either hold a `FileDescriptor` or a `DispatchIO`. We create `DispatchIO` as the last step of `spawn()` and use it to perform read/write, as well as cleanup instead of using a raw file descriptor.
@iCharlesHu iCharlesHu force-pushed the charles/fork-exec-signals branch from a56ee26 to 1a91649 Compare May 1, 2025 05:50
@iCharlesHu iCharlesHu merged commit c0bbfa5 into swiftlang:main May 1, 2025
20 checks passed
@iCharlesHu iCharlesHu deleted the charles/fork-exec-signals branch May 1, 2025 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants