clean up the code, and replace GDK X error handler with one that chains up

2001-09-01  Havoc Pennington  <hp@pobox.com>

	* src/errors.c: clean up the code, and replace GDK X error handler
	with one that chains up to GDK but first logs the error to logfile.
This commit is contained in:
Havoc Pennington 2001-09-01 05:53:07 +00:00 committed by Havoc Pennington
parent 501dd26713
commit 2a0a5dfdf8
3 changed files with 33 additions and 92 deletions

View File

@ -1,3 +1,8 @@
2001-09-01 Havoc Pennington <hp@pobox.com>
* src/errors.c: clean up the code, and replace GDK X error handler
with one that chains up to GDK but first logs the error to logfile.
2001-08-31 Havoc Pennington <hp@pobox.com> 2001-08-31 Havoc Pennington <hp@pobox.com>
* src/tabpopup.c (meta_ui_tab_popup_new): fix args to * src/tabpopup.c (meta_ui_tab_popup_new): fix args to

View File

@ -22,14 +22,13 @@
#include "errors.h" #include "errors.h"
#include <errno.h> #include <errno.h>
#include <stdlib.h>
#include <gdk/gdk.h> #include <gdk/gdk.h>
typedef struct _ErrorTrap ErrorTrap; static int (* saved_gdk_error_handler) (Display *display,
XErrorEvent *error);
struct _ErrorTrap static int (* saved_gdk_io_error_handler) (Display *display);
{
int error_code;
};
static int x_error_handler (Display *display, static int x_error_handler (Display *display,
XErrorEvent *error); XErrorEvent *error);
@ -38,104 +37,44 @@ static int x_io_error_handler (Display *display);
void void
meta_errors_init (void) meta_errors_init (void)
{ {
XSetErrorHandler (x_error_handler); saved_gdk_error_handler = XSetErrorHandler (x_error_handler);
XSetIOErrorHandler (x_io_error_handler); saved_gdk_io_error_handler = XSetIOErrorHandler (x_io_error_handler);
} }
void void
meta_error_trap_push (MetaDisplay *display) meta_error_trap_push (MetaDisplay *display)
{ {
ErrorTrap *et;
gdk_error_trap_push (); gdk_error_trap_push ();
return;
/* below here is old method */
et = g_new (ErrorTrap, 1);
et->error_code = Success;
display->error_traps = g_slist_prepend (display->error_traps, et);
} }
int int
meta_error_trap_pop (MetaDisplay *display) meta_error_trap_pop (MetaDisplay *display)
{ {
int result; /* just use GDK trap */
ErrorTrap *et;
GSList *next;
XSync (display->xdisplay, False); XSync (display->xdisplay, False);
return gdk_error_trap_pop (); return gdk_error_trap_pop ();
/* below here is old method */
if (display->error_traps == NULL)
meta_bug ("No error trap to pop\n");
XSync (display->xdisplay, False);
et = display->error_traps->data;
result = et->error_code;
next = display->error_traps->next;
g_slist_free_1 (display->error_traps);
display->error_traps = next;
g_free (et);
if (result != Success)
{
gchar buf[64];
XGetErrorText (display->xdisplay, result, buf, 63);
meta_verbose ("Popping error code %d (%s)\n",
result, buf);
} }
return result;
}
static int static int
x_error_handler (Display *xdisplay, x_error_handler (Display *xdisplay,
XErrorEvent *error) XErrorEvent *error)
{ {
if (error->error_code) int retval;
{
MetaDisplay *display;
display = meta_display_for_x_display (xdisplay);
if (display == NULL)
meta_bug ("Error received for unknown display?\n");
if (display->error_traps == NULL)
{
gchar buf[64]; gchar buf[64];
XGetErrorText (xdisplay, error->error_code, buf, 63); XGetErrorText (xdisplay, error->error_code, buf, 63);
meta_bug ("Received an X Window System error without handling it.\n" meta_verbose ("X error: %s serial %ld error_code %d request_code %d minor_code %d)\n",
"The error was '%s'.\n"
" (Details: serial %ld error_code %d request_code %d minor_code %d)\n",
buf, buf,
error->serial, error->serial,
error->error_code, error->error_code,
error->request_code, error->request_code,
error->minor_code); error->minor_code);
}
else
{
ErrorTrap *et;
et = display->error_traps->data; retval = saved_gdk_error_handler (xdisplay, error);
et->error_code = error->error_code; return retval;
}
}
return 0;
} }
static int static int
@ -162,11 +101,8 @@ x_io_error_handler (Display *xdisplay)
display->name); display->name);
} }
meta_display_close (display); /* Xlib would force an exit anyhow */
exit (1);
/* I believe Xlib will force an exit after we return, which
* seems sort of broken to me, but if true we should probably just
* exit for ourselves. But for now I'm not doing it.
*/
return 0; return 0;
} }

View File

@ -155,9 +155,6 @@ main (int argc, char **argv)
/* DO NOT FREE display_name, putenv() sucks */ /* DO NOT FREE display_name, putenv() sucks */
} }
/* gtk_init() below overrides this, so it can be removed */
meta_errors_init ();
g_type_init (); g_type_init ();
if (!disable_sm) if (!disable_sm)
@ -165,6 +162,9 @@ main (int argc, char **argv)
meta_ui_init (&argc, &argv); meta_ui_init (&argc, &argv);
/* must be after UI init so we can override GDK handlers */
meta_errors_init ();
if (!meta_display_open (NULL)) if (!meta_display_open (NULL))
meta_exit (META_EXIT_ERROR); meta_exit (META_EXIT_ERROR);