aboutsummaryrefslogtreecommitdiff
path: root/src/error.c
blob: af634a0195e004cf6f9d44e6e7ca8d92dc031a60 (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
 * @file error.c
 * @author Joe Wingbermuehle
 * @date 2004-2006
 *
 * @brief Error handling functions.
 *
 */

#include "jwm.h"
#include "error.h"
#include "main.h"

/** Log a fatal error and exit. */
void
FatalError(const char *str, ...)
{

	va_list ap;
	va_start(ap, str);

	Assert(str);

	fprintf(stderr, "JWM: error: ");
	vfprintf(stderr, str, ap);
	fprintf(stderr, "\n");

	va_end(ap);

	exit(1);

}

/** Log a warning. */
void
Warning(const char *str, ...)
{

	va_list ap;
	va_start(ap, str);

	Assert(str);

	WarningVA(NULL, str, ap);

	va_end(ap);

}

/** Log a warning. */
void
WarningVA(const char *part, const char *str, va_list ap)
{

	Assert(str);

	fprintf(stderr, "JWM: warning: ");
	if(part) {
		fprintf(stderr, "%s: ", part);
	}
	vfprintf(stderr, str, ap);
	fprintf(stderr, "\n");

}

/** Callback to handle errors from Xlib.
 * Note that if debug output is directed to an X terminal, emitting too
 * much output can cause a dead lock (this happens on HP-UX). Therefore
 * ShowCheckpoint isn't used by default.
 */
int
ErrorHandler(Display *d, XErrorEvent *e)
{

#ifdef DEBUG

	char buffer[64];
	char code[32];

#endif

	if(initializing) {
		if(e->request_code == X_ChangeWindowAttributes
			&& e->error_code == BadAccess) {
			FatalError("display is already managed");
		}
	}

#ifdef DEBUG

	if(!e) {
		fprintf(stderr, "XError: [no information]\n");
		return 0;
	}

	XGetErrorText(display, e->error_code, buffer, sizeof(buffer));
	Debug("XError: %s", buffer);

	snprintf(code, sizeof(code), "%d", e->request_code);
	XGetErrorDatabaseText(display, "XRequest", code, "?",
		buffer, sizeof(buffer));
	Debug("   Request Code: %d (%s)", e->request_code, buffer);
	Debug("   Minor Code: %d", e->minor_code);
	Debug("   Resource ID: 0x%lx", (unsigned long)e->resourceid);
	Debug("   Error Serial: %lu", (unsigned long)e->serial);

#if 0
	ShowCheckpoint();
#endif

#endif

	return 0;

}