diff --git a/src/modules/system/System.cpp b/src/modules/system/System.cpp index dd74c120f..8b1367f8b 100755 --- a/src/modules/system/System.cpp +++ b/src/modules/system/System.cpp @@ -28,6 +28,7 @@ #include //#include //#include +#include #include #elif defined(LOVE_WINDOWS) #include "common/utf8.h" @@ -41,6 +42,20 @@ namespace love namespace system { +System::System() +{ +#if defined(LOVE_LINUX) + // Enable automatic cleanup of zombie processes + struct sigaction act = {0}; + sigemptyset(&act.sa_mask); + act.sa_handler = SIG_DFL; + act.sa_flags = SA_NOCLDWAIT; + + // Requires linux 2.6 or higher, so anything remotely modern + sigaction(SIGCHLD, &act, nullptr); +#endif +} + std::string System::getOS() const { #if defined(LOVE_MACOSX) @@ -86,12 +101,14 @@ bool System::openURL(const std::string &url) const if (posix_spawnp(&pid, "xdg-open", nullptr, nullptr, const_cast(argv), environ) != 0) return false; - // Wait for xdg-open to complete (or fail.) + // Check if xdg-open already completed (or failed.) int status = 0; - if (waitpid(pid, &status, 0) == pid) + if (waitpid(pid, &status, WNOHANG) > 0) return (status == 0); else - return false; + // We can't tell what actually happens without waiting for + // the process to finish, which could take forever (literally). + return true; #elif defined(LOVE_WINDOWS) diff --git a/src/modules/system/System.h b/src/modules/system/System.h index 58eff3356..fb12b22fc 100644 --- a/src/modules/system/System.h +++ b/src/modules/system/System.h @@ -48,6 +48,7 @@ public: POWER_MAX_ENUM }; + System(); virtual ~System() {} // Implements Module.