[gcr] gck/gcr: Check result of write() in logger



commit a08eeffdcdda3ec69c77177927d78b2a282ef4a4
Author: Mathias Hasselmann <mathias openismus com>
Date:   Mon Nov 19 23:30:27 2012 +0100

    gck/gcr: Check result of write() in logger
    
     * Recent versions of libc mark the write() system call with
       the warn_unused_result attribute. This patch checks the
       result and disables logging if write() failed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688684

 gck/gck-debug.c |    7 ++++++-
 gcr/gcr-debug.c |    7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/gck/gck-debug.c b/gck/gck-debug.c
index 90cf215..7bd3c61 100644
--- a/gck/gck-debug.c
+++ b/gck/gck-debug.c
@@ -74,7 +74,12 @@ on_gck_log_debug (const gchar *log_domain,
 	                        (gulong)getpid (), log_domain,
 	                        message ? message : "(NULL) message");
 
-	write (1, gstring->str, gstring->len);
+	/*
+	 * Give up on debug messages if stdout got lost.
+	 */
+	if (write (1, gstring->str, gstring->len) != gstring->len)
+		current_flags = 0;
+
 	g_string_free (gstring, TRUE);
 }
 
diff --git a/gcr/gcr-debug.c b/gcr/gcr-debug.c
index 63bfb1d..172590b 100644
--- a/gcr/gcr-debug.c
+++ b/gcr/gcr-debug.c
@@ -88,7 +88,12 @@ on_gcr_log_debug (const gchar *log_domain,
 	                        (gulong)getpid (), log_domain,
 	                        message ? message : "(NULL) message");
 
-	write (1, gstring->str, gstring->len);
+	/*
+	 * Give up on debug messages if stdout got lost.
+	 */
+	if (write (1, gstring->str, gstring->len) != gstring->len)
+		current_flags = 0;
+
 	g_string_free (gstring, TRUE);
 }
 



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