Fix background process creation on macOS#15834
Open
jtainer wants to merge 1 commit into
Open
Conversation
Collaborator
|
I need to look at this PR more carefully when it isn't 5am here, but to be clear: this isn't a Mac-specific bug, this is a misuse of vfork() to assume you can alter the parent process's memory. The docs on some systems say that the new child process shares the parent's memory, but also POSIX says that you can just implement vfork() as fork()--indeed, this is exactly what macOS 12.0 did--in which case our current vfork hack will never work. The latest POSIX specs have outright removed vfork. The Linux manpages suggest there are (Linux-specific) benefits to using it, but we should probably just nuke it from orbit as too unsafe to trust, and use a mechanism like this PR on all platforms. |
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.
This fixes an issue on macOS where the PID of a background child process is never stored by the main process.
Description
Currently on macOS, when creating a process with
SDL_PROP_PROCESS_BACKGROUND_BOOLEAN=true, the PID returned byposix_spawnp()is never visible to the parent process, since it is stored in a different address space created byfork(). So, a PID of 0 is stored in in the parent process, and attempting to callKillProcess(child)actually sends the signal to the parent process. This issue did not occur on other posix systems since they usedvfork()instead offork(), allowing the child process to record the PID in the parent's address space directly.To resolve this, the process created by
fork()sends the PID returned byposix_spawnp()back to the parent process over a pipe. Additionally, I switched to usingfork()instead ofvfork()in all cases, for the sake of consistency and standard-compliance.Existing Issue(s)
N/A