#include #include static int nullHandler(Display *dpy, XErrorEvent *err) { puts("Got error"); return 0; } int main() { XInitThreads(); Display *dpy = XOpenDisplay(NULL); xcb_connection_t *c = XGetXCBConnection(dpy); uint32_t random_id = xcb_generate_id(c); XSetEventQueueOwner(dpy, XCBOwnsEventQueue); XSetErrorHandler(nullHandler); while (True) { /* First, let's make sure that Xlib has no idea what the current * sequence number is. */ for (int i = 0; i < (2<<16)+(2<<14); i++) { xcb_no_operation(c); } puts("Done with the NoOperation requests"); /* Finally, let's break Xlib */ /* Xlib makes sure that it will handle the error (if any) for * this request: append_pending_request() in xcb_io.c */ XCreateWindow(dpy, random_id, 0, 0, 10, 10, 0, 24, InputOutput, CopyFromParent, 0, NULL); /* _XReply() now handles the previous pending request and gets * the error. While calling the error handler, it will deadlock. */ XCreateWindow(dpy, random_id, 0, 0, 10, 10, 0, 24, InputOutput, CopyFromParent, 0, NULL); puts("Oh shit, it survived?!"); } }