-
Notifications
You must be signed in to change notification settings - Fork 397
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
Reap zombie processes left behind by openURL #1928
Open
pfirsich
wants to merge
1
commit into
love2d:main
Choose a base branch
from
pfirsich:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,13 +53,43 @@ | |
#endif | ||
#endif | ||
|
||
#if defined(LOVE_LINUX) | ||
#include <unordered_set> | ||
|
||
static std::unordered_set<pid_t>& getSpawnedPids() | ||
{ | ||
static std::unordered_set<pid_t> spawnedPids; | ||
return spawnedPids; | ||
} | ||
|
||
static void sigchldHandler(int signo, siginfo_t* info, void* /*context*/) | ||
{ | ||
// We need to be selective when reaping child processes, because simply calling | ||
// `waitpid` on every child process that terminated will break any other calls | ||
// to `waitpid`. | ||
// Particularly `os.execute` (internally: `system`) will always return -1, because | ||
// their call to `waitpid` returned `ECHILD`, since we already reaped the process. | ||
// This was reported in #1047 and fixed with a similar approach in 30ff7d4 and f7d226d | ||
// and then later removed in a4a62f3. | ||
if (getSpawnedPids().erase(info->si_pid) > 0) | ||
::waitpid(info->si_pid, nullptr, 0); | ||
} | ||
#endif | ||
|
||
namespace love | ||
{ | ||
namespace system | ||
{ | ||
|
||
System::System() | ||
{ | ||
#if defined(LOVE_LINUX) | ||
struct sigaction sa; | ||
sa.sa_sigaction = sigchldHandler; | ||
sigemptyset(&sa.sa_mask); | ||
sa.sa_flags = SA_RESTART | SA_SIGINFO; | ||
sigaction(SIGCHLD, &sa, nullptr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this get cleaned up / reset when the |
||
#endif | ||
} | ||
|
||
std::string System::getOS() const | ||
|
@@ -131,6 +161,8 @@ bool System::openURL(const std::string &url) const | |
} | ||
#endif | ||
|
||
getSpawnedPids().insert(pid); | ||
|
||
// Check if xdg-open already completed (or failed.) | ||
int status = 0; | ||
if (waitpid(pid, &status, WNOHANG) > 0) | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very unfamiliar with these APIs so this might be a silly question: is it possible for this callback to be called on other threads, or is it guaranteed to only be called on the main thread?
If it can be called on other threads there'll need to be some extra thread safety (maybe a mutex) when modifying
spawnedPids
.