forked from QubesOS/qubes-gui-daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.c
92 lines (86 loc) · 3.08 KB
/
error.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* The Qubes OS Project, http://www.qubes-os.org
*
* Copyright (C) 2010 Rafal Wojtczuk <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xlibint.h>
int dummy_handler(Display * dpy, XErrorEvent * ev)
{
#define ERROR_BUF_SIZE 256
char buf[ERROR_BUF_SIZE];
char request[ERROR_BUF_SIZE];
_XExtension *ext = NULL;
XGetErrorText(dpy, ev->error_code, buf, sizeof(buf));
fprintf(stderr, "ErrorHandler: %s\n", buf);
/* Find major opcode name */
if (ev->request_code < 128) {
snprintf(request, sizeof(request), "%d", ev->request_code);
XGetErrorDatabaseText(dpy, "XRequest", request, "", buf,
sizeof(buf));
} else {
for (ext = dpy->ext_procs;
ext && ext->codes.major_opcode != ev->request_code;
ext = ext->next);
if (ext) {
strncpy(buf, ext->name, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0';
} else {
buf[0] = '\0';
}
}
fprintf(stderr, " Major opcode: %d (%s)\n",
ev->request_code, buf);
/* Find minor opcode name */
if (ev->request_code >= 128 && ext) {
snprintf(request, sizeof(request), "%d", ev->request_code);
snprintf(request, sizeof(request), "%s.%d",
ext->name, ev->minor_code);
XGetErrorDatabaseText(dpy, "XRequest", request, "", buf,
sizeof(buf));
fprintf(stderr, " Minor opcode: %d (%s)\n",
ev->minor_code, buf);
} else {
fprintf(stderr, " Minor opcode: %d\n",
ev->minor_code);
}
/* Provide value information */
switch (ev->error_code) {
case BadValue:
fprintf(stderr, " Value: 0x%x\n",
(int) ev->resourceid);
break;
case BadAtom:
fprintf(stderr, " AtomID: 0x%x\n",
(int) ev->resourceid);
break;
default:
fprintf(stderr, " ResourceID: 0x%x\n",
(int) ev->resourceid);
break;
}
/* Provide serial number information */
fprintf(stderr, " Failed serial number: %ld\n",
ev->serial);
fprintf(stderr, " Current serial number: %ld\n",
dpy->request);
return 0;
}