summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-05-01 09:59:05 -0400
committerDan Winship <danw@gnome.org>2014-05-01 10:00:52 -0400
commitaf335417fce4a6166370c13f6ae72816c5c125f0 (patch)
treebd0442abcc281e9bfb5eedb6ab271f7814238c7d
parenta65c2fc21e252ccaab478da6afc5a1c0058f623f (diff)
downloadglib-wip/nosigpipe.tar.gz
gsocket: Set SO_NOSIGPIPE on sockets on Darwinwip/nosigpipe
This is a best-effort approach to preventing SIGPIPE emissions on Darwin and iOS, where they continue to be intercepted by the Xcode debugger even if SIG_IGN prevents them crashing the program. This is similar to the existing code which sets MSG_NOSIGNAL on all send() calls. MSG_NOSIGNAL doesn't exist on Darwin though. Based on a patch from Philip Withnall. https://bugzilla.gnome.org/show_bug.cgi?id=728730
-rw-r--r--gio/gsocket.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/gio/gsocket.c b/gio/gsocket.c
index 2f7f0dc1f..ed496a624 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -579,6 +579,11 @@ g_socket_constructed (GObject *object)
g_warning ("Error setting socket status flags: %s", socket_strerror (errsv));
}
#endif
+
+#ifdef SO_NOSIGPIPE
+ /* See note about SIGPIPE below. */
+ g_socket_set_option (socket, SOL_SOCKET, SO_NOSIGPIPE, TRUE, NULL);
+#endif
}
}
@@ -767,6 +772,11 @@ g_socket_class_init (GSocketClass *klass)
/* There is no portable, thread-safe way to avoid having the process
* be killed by SIGPIPE when calling send() or sendmsg(), so we are
* forced to simply ignore the signal process-wide.
+ *
+ * Even if we ignore it though, gdb will still stop if the app
+ * receives a SIGPIPE, which can be confusing and annoying. So when
+ * possible, we also use MSG_NOSIGNAL / SO_NOSIGPIPE elsewhere to
+ * prevent the signal from occurring at all.
*/
signal (SIGPIPE, SIG_IGN);
#endif
@@ -2677,10 +2687,7 @@ g_socket_receive_from (GSocket *socket,
error);
}
-/* Although we ignore SIGPIPE, gdb will still stop if the app receives
- * one, which can be confusing and annoying. So if possible, we want
- * to suppress the signal entirely.
- */
+/* See the comment about SIGPIPE above. */
#ifdef MSG_NOSIGNAL
#define G_SOCKET_DEFAULT_SEND_FLAGS MSG_NOSIGNAL
#else