Ignore SIGPIPE so we dont crash on broken pipes

This commit is contained in:
Lion Kortlepel
2020-11-09 23:34:44 +01:00
parent 2d11841a68
commit 60c7997c6b
+19 -1
View File
@@ -1,9 +1,22 @@
#include "CustomAssert.h" #include "CustomAssert.h"
#include <curl/curl.h> #include <curl/curl.h>
#include "Startup.h" #include "Startup.h"
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include "Security/Xor.h"
#ifndef WIN32
#include <signal.h>
void UnixSignalHandler(int sig) {
switch (sig) {
case SIGPIPE:
warn(Sec("ignored signal SIGPIPE: Pipe broken"));
break;
default:
error(Sec("Signal arrived in handler but was not handled: ") + std::to_string(sig));
break;
}
}
#endif // WIN32
[[noreturn]] void loop(){ [[noreturn]] void loop(){
DebugPrintTID(); DebugPrintTID();
@@ -15,6 +28,11 @@
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
try { try {
#ifndef WIN32
// ignore SIGPIPE, the signal that is sent for example when a client
// disconnects while data is being sent to him ("broken pipe").
signal(SIGPIPE, UnixSignalHandler);
#endif // WIN32
DebugPrintTID(); DebugPrintTID();
// curl needs to be initialized to properly deallocate its resources later // curl needs to be initialized to properly deallocate its resources later
Assert(curl_global_init(CURL_GLOBAL_DEFAULT) == CURLE_OK); Assert(curl_global_init(CURL_GLOBAL_DEFAULT) == CURLE_OK);