OSDN Git Service

core: Use daemon specific GLib logging handling for backtraces
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 11 Nov 2015 14:09:02 +0000 (15:09 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 11 Nov 2015 14:09:02 +0000 (15:09 +0100)
src/main.c

index 2001cee..ebc93f5 100644 (file)
@@ -361,6 +361,21 @@ static void init_defaults(void)
        main_opts.did_version = (major << 8 | minor);
 }
 
+static void log_handler(const gchar *log_domain, GLogLevelFlags log_level,
+                               const gchar *message, gpointer user_data)
+{
+       int priority;
+
+       if (log_level & (G_LOG_LEVEL_ERROR |
+                               G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING))
+               priority = 0x03;
+       else
+               priority = 0x06;
+
+       btd_log(0xffff, priority, "GLib: %s", message);
+       btd_backtrace(0xffff);
+}
+
 static GMainLoop *event_loop;
 
 void btd_exit(void)
@@ -594,6 +609,10 @@ int main(int argc, char *argv[])
 
        __btd_log_init(option_debug, option_detach);
 
+       g_log_set_handler("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL |
+                                                       G_LOG_FLAG_RECURSION,
+                                                       log_handler, NULL);
+
        sd_notify(0, "STATUS=Starting up");
 
        main_conf = load_config(CONFIGDIR "/main.conf");