[Xcb] [PATCH:xwininfo 2/2] Print more detailed error messages when xcb_connect fails
Alan Coopersmith
alan.coopersmith at oracle.com
Sat Aug 25 14:23:46 PDT 2012
Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
dsimple.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
A little bit nicer for users, and gives us a way to test the connection error
reporting code.
Verified all 4 possible error codes are reported as expected:
% sh -c 'ulimit -d 50 ; ./xwininfo -root -display :0'
./xwininfo: error: Failed to allocate memory in xcb_connect
% ./xwininfo -root -display sdfgkjng
./xwininfo: error: unable to parse display name "sdfgkjng"
% ./xwininfo -root -display :0.100
./xwininfo: error: invalid screen 100 in display ":0.100"
% ./xwininfo -root -display :100
./xwininfo: error: unable to open display ":100"
diff --git a/dsimple.c b/dsimple.c
index 51fb231..6432e13 100644
--- a/dsimple.c
+++ b/dsimple.c
@@ -108,13 +108,26 @@ void Setup_Display_And_Screen (
xcb_connection_t **dpy, /* MODIFIED */
xcb_screen_t **screen) /* MODIFIED */
{
- int screen_number, i;
+ int screen_number, i, err;
/* Open Display */
*dpy = xcb_connect (display_name, &screen_number);
- if (xcb_connection_has_error (*dpy)) {
- Fatal_Error ("unable to open display \"%s\"",
- Get_Display_Name(display_name) );
+ if ((err = xcb_connection_has_error (*dpy)) != 0) {
+ switch (err) {
+ case XCB_CONN_CLOSED_MEM_INSUFFICIENT:
+ Fatal_Error ("Failed to allocate memory in xcb_connect");
+ case XCB_CONN_CLOSED_PARSE_ERR:
+ Fatal_Error ("unable to parse display name \"%s\"",
+ Get_Display_Name(display_name) );
+#ifdef XCB_CONN_CLOSED_INVALID_SCREEN
+ case XCB_CONN_CLOSED_INVALID_SCREEN:
+ Fatal_Error ("invalid screen %d in display \"%s\"",
+ screen_number, Get_Display_Name(display_name));
+#endif
+ default:
+ Fatal_Error ("unable to open display \"%s\"",
+ Get_Display_Name(display_name) );
+ }
}
if (screen) {
--
1.7.9.2
More information about the Xcb
mailing list