From 6b78364eabd0fefec69db752fc0263ec662cd5b2 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 21 Jul 2024 14:22:33 +1000 Subject: [PATCH] Sockets: Ignore SIGPIPE on Linux Stops our process terminating if the socket is disconnected mid-write. --- src/util/platform_misc_unix.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/util/platform_misc_unix.cpp b/src/util/platform_misc_unix.cpp index cafc04d4d..2ffbaf42d 100644 --- a/src/util/platform_misc_unix.cpp +++ b/src/util/platform_misc_unix.cpp @@ -4,6 +4,7 @@ #include "input_manager.h" #include "platform_misc.h" +#include "common/error.h" #include "common/log.h" #include "common/path.h" #include "common/scoped_guard.h" @@ -11,6 +12,7 @@ #include #include +#include #include #include @@ -18,6 +20,13 @@ Log_SetChannel(PlatformMisc); bool PlatformMisc::InitializeSocketSupport(Error* error) { + // Ignore SIGPIPE, we handle errors ourselves. + if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) + { + Error::SetErrno(error, "signal(SIGPIPE, SIG_IGN) failed: ", errno); + return false; + } + return true; }