mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-03 16:36:25 +00:00
Allow the use of posix_spawn() instead of vfork/execlp()
This commit is contained in:
@@ -28,11 +28,25 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <errno.h>
|
||||
#if USE_POSIX_SPAWN
|
||||
#include <spawn.h>
|
||||
extern char **environ;
|
||||
#endif
|
||||
|
||||
int SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
const pid_t pid1 = fork();
|
||||
if (pid1 == 0) { /* child process */
|
||||
#if USE_POSIX_SPAWN
|
||||
pid_t pid2;
|
||||
const char *args[] = { "xdg-open", url, NULL };
|
||||
if (posix_spawnp(&pid2, args[0], NULL, NULL, (char **)args, environ) == 0) {
|
||||
/* Child process doesn't wait for possibly-blocking grandchild. */
|
||||
_exit(EXIT_SUCCESS);
|
||||
} else {
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
#else
|
||||
pid_t pid2;
|
||||
/* Clear LD_PRELOAD so Chrome opens correctly when this application is launched by Steam */
|
||||
unsetenv("LD_PRELOAD");
|
||||
@@ -47,6 +61,7 @@ int SDL_SYS_OpenURL(const char *url)
|
||||
/* Child process doesn't wait for possibly-blocking grandchild. */
|
||||
_exit(EXIT_SUCCESS);
|
||||
}
|
||||
#endif
|
||||
} else if (pid1 < 0) {
|
||||
return SDL_SetError("fork() failed: %s", strerror(errno));
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user