[glib] glog: fix crash on Linux without stderr stream



commit 15faf0ef62c3053292eb67a93fdbf6c72762112b
Author: INSUN PYO <insun pyo samsung com>
Date:   Fri Aug 18 13:42:44 2017 +0900

    glog: fix crash on Linux without stderr stream
    
    0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:58
    1  0xb67c43f0 in __GI_abort () at abort.c:89
    2  0xb69ee9d8 in _g_log_abort (breakpoint=2, breakpoint@entry=1) at gmessages.c:548
    3  0xb69ef692 in g_logv (log_domain=0xb6a1dfc8 "GLib", log_level=-1254563840, 
log_level@entry=G_LOG_LEVEL_CRITICAL, format=format@entry=0xb6a26a48 "%s: assertion '%s' failed", args=..., 
args@entry=...) at gmessages.c:1357
    4  0xb69ef728 in g_log (log_domain=<optimized out>, log_level=log_level@entry=G_LOG_LEVEL_CRITICAL, 
format=0xb6a26a48 "%s: assertion '%s' failed") at gmessages.c:1398
    5  0xb69efa5a in g_return_if_fail_warning (log_domain=<optimized out>, pretty_function=<optimized out>, 
expression=<optimized out>) at gmessages.c:2687
    6  0xb69efe7c in g_log_writer_is_journald (output_fd=-1) at gmessages.c:2122
    7  0xb69f02a2 in g_log_writer_default (log_level=G_LOG_LEVEL_CRITICAL, fields=0xbedc9d00, n_fields=4, 
user_data=0x0) at gmessages.c:2584
    8  0xb69ef21a in g_log_structured_array (log_level=G_LOG_LEVEL_CRITICAL, fields=0xbedc9d00, n_fields=4) 
at gmessages.c:1933
    9  0xb69ef47e in g_log_default_handler (log_domain=0xb6a1dfc8 "GLib", log_level=G_LOG_LEVEL_CRITICAL, 
message=<optimized out>, unused_data=<optimized out>) at gmessages.c:3036
    10 0xb69ef5fc in g_logv (log_domain=0xb6a1dfc8 "GLib", log_level=log_level@entry=G_LOG_LEVEL_CRITICAL, 
format=format@entry=0xb6a26a48 "%s: assertion '%s' failed", args=..., args@entry=...) at gmessages.c:1336
    11 0xb69ef728 in g_log (log_domain=<optimized out>, log_level=log_level@entry=G_LOG_LEVEL_CRITICAL, 
format=0xb6a26a48 "%s: assertion '%s' failed") at gmessages.c:1398
    12 0xb69efa5a in g_return_if_fail_warning (log_domain=<optimized out>, pretty_function=<optimized out>, 
expression=<optimized out>) at gmessages.c:2687
    
    If stderr is not associated with an output stream, the fileno(stderr) returned is -1.
    So, g_return_if_fail_warning is recursively called and the abort occurs on the second call.
    
    Modified by Philip Withnall to include mention this in the
    documentation.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786452

 glib/gmessages.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/glib/gmessages.c b/glib/gmessages.c
index 5979f64..f3e343b 100644
--- a/glib/gmessages.c
+++ b/glib/gmessages.c
@@ -2114,6 +2114,12 @@ open_journal (void)
  * systemd journal, or something else (like a log file or `stdout` or
  * `stderr`).
  *
+ * Invalid file descriptors are accepted and return %FALSE, which allows for
+ * the following construct without needing any additional error handling:
+ * |[<!-- language="C" -->
+ *   is_journald = g_log_writer_is_journald (fileno (stderr));
+ * ]|
+ *
  * Returns: %TRUE if @output_fd points to the journal, %FALSE otherwise
  * Since: 2.50
  */
@@ -2127,7 +2133,8 @@ g_log_writer_is_journald (gint output_fd)
   static gsize initialized;
   static gboolean fd_is_journal = FALSE;
 
-  g_return_val_if_fail (output_fd >= 0, FALSE);
+  if (output_fd < 0)
+    return FALSE;
 
   if (g_once_init_enter (&initialized))
     {


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