From 170441313cc07b4563d10f0a5c04bdf801b59277 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 2 Apr 2022 16:07:51 -0700 Subject: [PATCH] Net: Ignore SIGPIPE errors on POSIX systems. This should work on BSD/macOS/Linux/iOS/similar. --- .editorconfig | 4 ++++ Qt/QtMain.cpp | 6 ++++++ SDL/SDLMain.cpp | 6 ++++++ SDL/SDLMain.mm | 6 ++++++ headless/Headless.cpp | 7 +++++++ ios/main.mm | 6 ++++++ 6 files changed, 35 insertions(+) diff --git a/.editorconfig b/.editorconfig index 48cd05a99e..7c6f14d27f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -32,3 +32,7 @@ charset = utf-8 [libretro/**.{cpp,h}] indent_style = space indent_size = 3 + +[SDL/SDLMain.mm] +indent_style = space +indent_size = 4 diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index e3b3829177..c0d7d7b05b 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -48,6 +48,7 @@ #include "Core/ConfigValues.h" #include "Core/HW/Camera.h" +#include #include MainUI *emugl = nullptr; @@ -710,6 +711,11 @@ int main(int argc, char *argv[]) } } + // Ignore sigpipe. + if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { + perror("Unable to ignore SIGPIPE"); + } + PROFILE_INIT(); glslang::InitializeProcess(); #if defined(Q_OS_LINUX) diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index 8795307309..5ccfcb312b 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -18,6 +18,7 @@ SDLJoystick *joystick = NULL; #include #include #include +#include #include #include @@ -519,6 +520,11 @@ int main(int argc, char *argv[]) { #ifdef HAVE_LIBNX socketInitializeDefault(); nxlinkStdio(); +#else // HAVE_LIBNX + // Ignore sigpipe. + if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { + perror("Unable to ignore SIGPIPE"); + } #endif // HAVE_LIBNX PROFILE_INIT(); diff --git a/SDL/SDLMain.mm b/SDL/SDLMain.mm index 7819ad0c09..4709e8f5f8 100644 --- a/SDL/SDLMain.mm +++ b/SDL/SDLMain.mm @@ -8,6 +8,7 @@ #include "SDL.h" #include "SDLMain.h" #include "Common/Profiler/Profiler.h" +#include #include /* for MAXPATHLEN */ #include @@ -374,6 +375,11 @@ int main (int argc, char **argv) PROFILE_INIT(); + // Ignore sigpipe. + if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { + perror("Unable to ignore SIGPIPE"); + } + #if SDL_USE_NIB_FILE NSApplicationMain (argc, argv); #else diff --git a/headless/Headless.cpp b/headless/Headless.cpp index c33609db3d..d04ec974e3 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -17,6 +17,8 @@ #include "Common/CommonWindows.h" #if PPSSPP_PLATFORM(WINDOWS) #include +#else +#include #endif #include "Common/CPUDetect.h" #include "Common/File/VFS/VFS.h" @@ -246,6 +248,11 @@ int main(int argc, const char* argv[]) PROFILE_INIT(); #if PPSSPP_PLATFORM(WINDOWS) timeBeginPeriod(1); +#else + // Ignore sigpipe. + if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { + perror("Unable to ignore SIGPIPE"); + } #endif #if defined(_DEBUG) && defined(_MSC_VER) diff --git a/ios/main.mm b/ios/main.mm index e53b7c7abf..5413be1dd6 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -4,6 +4,7 @@ #import #import #import +#import #import #import #import @@ -270,6 +271,11 @@ int main(int argc, char *argv[]) PROFILE_INIT(); + // Ignore sigpipe. + if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { + perror("Unable to ignore SIGPIPE"); + } + @autoreleasepool { return UIApplicationMain(argc, argv, NSStringFromClass([PPSSPPUIApplication class]), NSStringFromClass([AppDelegate class])); }