1 /*
2 * $Id: errors.c,v 1.1 2005-09-18 22:05:32 dhmunro Exp $
3 * X11 error handling
4 */
5 /* Copyright (c) 2005, The Regents of the University of California.
6 * All rights reserved.
7 * This file is part of yorick (http://yorick.sourceforge.net).
8 * Read the accompanying LICENSE file for details.
9 */
10
11 #include "config.h"
12 #include "playx.h"
13 #include "playu.h"
14 #include "pstdlib.h"
15
16 #include <string.h>
17
18 static char x11_errmsg[90];
19 static int x11_nerrs = 0;
20
21 int
x_err_handler(Display * dpy,XErrorEvent * event)22 x_err_handler(Display *dpy, XErrorEvent *event)
23 {
24 if (!p_signalling) {
25 strcpy(x11_errmsg, "Xlib: ");
26 XGetErrorText(dpy, event->error_code, x11_errmsg+6, 83);
27 x11_errmsg[89] = '\0';
28 u_errmsg = x11_errmsg;
29 p_signalling = PSIG_SOFT;
30 x11_nerrs = 1;
31 } else {
32 x11_nerrs++;
33 }
34 /* Xlib apparently ignores return value
35 * - must return here, or Xlib internal data structures trashed
36 * - therefore actual error processing delayed (u_error must return) */
37 return 1;
38 }
39
40 int
x_panic(Display * dpy)41 x_panic(Display *dpy)
42 {
43 x_display *xdpy = x_dpy(dpy);
44
45 if (xdpy) {
46 /* attempt to close display to free all associated Xlib structs
47 * -- study of xfree86 source indicates that first call to
48 * XCloseDisplay might well end up calling x_panic
49 * recursively, but a second call might succeed */
50 xdpy->panic++;
51 while (xdpy->screens) p_disconnect(xdpy->screens);
52 if (xdpy->panic<3) XCloseDisplay(dpy);
53 xdpy->dpy = 0;
54 p_free(xdpy); /* x_disconnect will not have done this */
55 }
56
57 p_abort();
58 return 1; /* Xlib will call exit! */
59 }
60