From 418303a1ffe37fe8dc0332d0fbe112ccc2a3756b Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Wed, 24 Sep 2014 17:22:27 +0000 Subject: [PATCH] Linux: Install xlib error handlers to avoid crash on X11 error (issue #1337). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1844 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- tests/cefclient/cefclient_gtk.cpp | 20 ++++++++++++++++++ tests/cefsimple/cefsimple_linux.cpp | 27 ++++++++++++++++++++++++ tests/unittests/run_all_unittests.cc | 31 ++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/tests/cefclient/cefclient_gtk.cpp b/tests/cefclient/cefclient_gtk.cpp index 1b4bf347f..46222cbd2 100644 --- a/tests/cefclient/cefclient_gtk.cpp +++ b/tests/cefclient/cefclient_gtk.cpp @@ -46,6 +46,21 @@ class MainBrowserProvider : public OSRBrowserProvider { } } g_main_browser_provider; +int XErrorHandlerImpl(Display *display, XErrorEvent *event) { + LOG(WARNING) + << "X error received: " + << "type " << event->type << ", " + << "serial " << event->serial << ", " + << "error_code " << static_cast(event->error_code) << ", " + << "request_code " << static_cast(event->request_code) << ", " + << "minor_code " << static_cast(event->minor_code); + return 0; +} + +int XIOErrorHandlerImpl(Display *display) { + return 0; +} + void destroy(GtkWidget* widget, gpointer data) { // Quitting CEF is handled in ClientHandler::OnBeforeClose(). } @@ -403,6 +418,11 @@ int main(int argc, char* argv[]) { // Populate the settings based on command line arguments. AppGetSettings(settings); + // Install xlib error handlers so that the application won't be terminated + // on non-fatal errors. + XSetErrorHandler(XErrorHandlerImpl); + XSetIOErrorHandler(XIOErrorHandlerImpl); + // Initialize CEF. CefInitialize(main_args, settings, app.get(), NULL); diff --git a/tests/cefsimple/cefsimple_linux.cpp b/tests/cefsimple/cefsimple_linux.cpp index 18f9c711f..428ccc15f 100644 --- a/tests/cefsimple/cefsimple_linux.cpp +++ b/tests/cefsimple/cefsimple_linux.cpp @@ -4,6 +4,28 @@ #include "cefsimple/simple_app.h" +#include + +namespace { + +int XErrorHandlerImpl(Display *display, XErrorEvent *event) { + LOG(WARNING) + << "X error received: " + << "type " << event->type << ", " + << "serial " << event->serial << ", " + << "error_code " << static_cast(event->error_code) << ", " + << "request_code " << static_cast(event->request_code) << ", " + << "minor_code " << static_cast(event->minor_code); + return 0; +} + +int XIOErrorHandlerImpl(Display *display) { + return 0; +} + +} // namespace + + // Entry point function for all processes. int main(int argc, char* argv[]) { // Provide CEF with command-line arguments. @@ -25,6 +47,11 @@ int main(int argc, char* argv[]) { // Specify CEF global settings here. CefSettings settings; + // Install xlib error handlers so that the application won't be terminated + // on non-fatal errors. + XSetErrorHandler(XErrorHandlerImpl); + XSetIOErrorHandler(XIOErrorHandlerImpl); + // Initialize CEF for the browser process. CefInitialize(main_args, settings, app.get(), NULL); diff --git a/tests/unittests/run_all_unittests.cc b/tests/unittests/run_all_unittests.cc index acbbff030..0604b92ef 100644 --- a/tests/unittests/run_all_unittests.cc +++ b/tests/unittests/run_all_unittests.cc @@ -5,6 +5,13 @@ // Include this first to avoid type conflicts with CEF headers. #include "tests/unittests/chromium_includes.h" +#if defined(OS_LINUX) +#include +// Definitions conflict with gtest. +#undef None +#undef Bool +#endif + #include "base/threading/thread.h" #include "include/base/cef_bind.h" @@ -56,6 +63,23 @@ void RunTests(CefTestThread* thread) { base::Bind(&CefTestThread::RunTests, base::Unretained(thread))); } +#if defined(OS_LINUX) +int XErrorHandlerImpl(Display *display, XErrorEvent *event) { + LOG(WARNING) + << "X error received: " + << "type " << event->type << ", " + << "serial " << event->serial << ", " + << "error_code " << static_cast(event->error_code) << ", " + << "request_code " << static_cast(event->request_code) << ", " + << "minor_code " << static_cast(event->minor_code); + return 0; +} + +int XIOErrorHandlerImpl(Display *display) { + return 0; +} +#endif // defined(OS_LINUX) + } // namespace @@ -102,6 +126,13 @@ int main(int argc, char* argv[]) { PlatformInit(); #endif +#if defined(OS_LINUX) + // Install xlib error handlers so that the application won't be terminated + // on non-fatal errors. + XSetErrorHandler(XErrorHandlerImpl); + XSetIOErrorHandler(XIOErrorHandlerImpl); +#endif + // Initialize CEF. CefInitialize(main_args, settings, app, windows_sandbox_info);