2 /* This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * This function should be used by all modules and fvwm when a X error
19 * occurs and the module exits.
27 #include "FRenderInit.h"
29 #undef XSetErrorHandler
31 #define USE_GET_ERROR_TEXT 1
32 #ifndef USE_GET_ERROR_TEXT
33 static char *error_name(unsigned char code
);
35 static char *request_name(unsigned char code
);
36 static char unknown
[32];
38 void do_coredump(void)
40 fprintf(stderr
, " Leaving a core dump now\n");
48 /* exit if this fails */
52 #define USE_GET_ERROR_TEXT 1
53 void PrintXErrorAndCoredump(Display
*dpy
, XErrorEvent
*error
, char *MyName
)
59 #ifdef USE_GET_ERROR_TEXT
60 /* can't call this from within an error handler! */
61 /* DV (21-Nov-2000): Well, actually we *can* call it in an error
62 * handler since it does not trigger a protocol request. */
63 if (error
->error_code
>= FirstExtensionError
)
65 suc
= FRenderGetErrorText(error
->error_code
, msg
);
68 XGetErrorText(dpy
, error
->error_code
, msg
, sizeof(msg
));
69 fprintf(stderr
,"%s: Cause of next X Error.\n", MyName
);
70 fprintf(stderr
, " Error: %d (%s)\n", error
->error_code
, msg
);
72 fprintf(stderr
,"%s: Cause of next X Error.\n", MyName
);
73 if (error
->error_code
>= FirstExtensionError
)
75 suc
= FRenderGetErrorText(error
->error_code
, msg
);
78 fprintf(stderr
, " Error: %d (%s)\n",
79 error
->error_code
, msg
);
81 fprintf(stderr
, " Error: %d (%s)\n",
82 error
->error_code
, error_name(error
->error_code
));
84 fprintf(stderr
, " Major opcode of failed request: %d (%s)\n",
85 error
->request_code
, request_name(error
->request_code
));
86 fprintf(stderr
, " Minor opcode of failed request: %d \n",
88 /* error->resourceid may be uninitialised. This is no proble since we
89 * are dumping core anyway. */
90 fprintf(stderr
, " Resource id of failed request: 0x%lx \n",
93 /* leave a coredump */
97 #ifndef USE_GET_ERROR_TEXT
98 /* this comes out of X.h */
99 static char *error_names
[] = {
119 static char *error_name(unsigned char code
)
121 if (code
== 0 || code
> (sizeof(error_names
) / sizeof(char *)))
123 sprintf(unknown
, "Unknown: %d", (int)code
);
126 return error_names
[code
- 1];
130 /* this comes out of Xproto.h */
131 static char *code_names
[] = {
133 "ChangeWindowAttributes",
134 "GetWindowAttributes",
161 "ChangeActivePointerGrab",
211 "CopyColormapAndFree",
214 "ListInstalledColormaps",
231 "ChangeKeyboardMapping",
232 "GetKeyboardMapping",
233 "ChangeKeyboardControl",
234 "GetKeyboardControl",
236 "ChangePointerControl",
249 "SetModifierMapping",
250 "GetModifierMapping",
253 static char *request_name(unsigned char code
)
255 if (code
== 0 || code
> (sizeof(code_names
) / sizeof(char *)))
257 if (code
== FRenderGetMajorOpCode())
259 sprintf(unknown
, "XRender");
263 sprintf(unknown
, "Unknown: %d", (int)code
);
267 return code_names
[code
- 1];
270 /* -------------------------- error handler stack -------------------------- */
272 static ferror_handler_t old_handler
= NULL
;
274 void ferror_set_temp_error_handler(ferror_handler_t new_handler
)
276 if (old_handler
!= NULL
)
280 old_handler
= XSetErrorHandler(old_handler
);
285 void ferror_reset_temp_error_handler(void)
287 if (old_handler
== NULL
)
291 XSetErrorHandler(old_handler
);
297 int ferror_call_next_error_handler(Display
*dpy
, XErrorEvent
*error
)
301 if (old_handler
== NULL
)
305 rc
= old_handler(dpy
, error
);