[glib] Ignore SIGPIPE when using GSocket



commit 25800ed4a393f7edbea179aa86907079a58fd097
Author: Dan Winship <danw gnome org>
Date:   Sun May 17 20:44:54 2009 -0400

    Ignore SIGPIPE when using GSocket
    
    http://bugzilla.gnome.org/show_bug.cgi?id=583001
---
 gio/gsocket.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/gio/gsocket.c b/gio/gsocket.c
index 4d33394..03944d6 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -28,6 +28,7 @@
 #include "config.h"
 
 #include <errno.h>
+#include <signal.h>
 #include <string.h>
 #include <stdlib.h>
 
@@ -102,6 +103,12 @@
  *
  * All socket file descriptors are set to be close-on-exec.
  *
+ * Note that creating a #GSocket causes the signal %SIGPIPE to be
+ * ignored for the remainder of the program. If you are writing a
+ * command-line utility that uses #GSocket, you may need to take into
+ * account the fact that your program will not automatically be killed
+ * if it tries to write to %stdout after it has been closed.
+ *
  * Since: 2.22
  **/
 
@@ -616,6 +623,14 @@ g_socket_class_init (GSocketClass *klass)
   /* Make sure winsock has been initialized */
   type = g_inet_address_get_type ();
 
+#ifdef SIGPIPE
+  /* 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.
+   */
+  signal (SIGPIPE, SIG_IGN);
+#endif
+
   g_type_class_add_private (klass, sizeof (GSocketPrivate));
 
   gobject_class->finalize = g_socket_finalize;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]