--- xorg-server-1.7.6.901/hw/xfree86/common/xf86Events.c 2010-04-09 14:23:10.000000000 +0200 +++ xorg-server-1.7.6.901-PATCHED/hw/xfree86/common/xf86Events.c 2010-04-27 22:10:51.000000000 +0200 @@ -104,6 +104,21 @@ extern void (*xf86OSPMClose)(void); #endif +/* grab debugging */ +static ClientPtr debugGrabClient; + +void +xf86GrabCallback(CallbackListPtr *cbl, void *data, void *closure) +{ + ServerGrabInfoRec *grabinfo = data; + if (grabinfo == NULL) + return; + if (grabinfo->grabstate == SERVER_GRABBED) + debugGrabClient = grabinfo->client; + else if (grabinfo->grabstate == SERVER_UNGRABBED) + debugGrabClient = NULL; +} + static void xf86VTSwitch(void); /* @@ -424,6 +439,26 @@ } } +static void +kvetch_about_client(ClientPtr client, DeviceIntPtr device) +{ + LocalClientCredRec *lcc; + + ErrorF("Resource mask 0x%08x ", client->clientAsMask); + + if (device) { + ErrorF("device name \"%s\" ", device->name); + } + + if (GetLocalClientCreds(client, &lcc) != -1) { + ErrorF("euid %d egid %d pid %d", lcc->euid, lcc->egid, lcc->pid); + FreeLocalClientCreds(lcc); + } else { + ErrorF("(non-local)"); + } + ErrorF("\n\n"); +} + /* * xf86VTSwitch -- * Handle requests for switching the vt. @@ -529,6 +564,30 @@ if (xorgHWAccess) xf86DisableIO(); } + + /* grab debugging */ + if (debugGrabClient) { + ErrorF("Client holding server grab at VT switch:\n"); + kvetch_about_client(debugGrabClient, NULL); + } + + do { + DeviceIntPtr dev; + for (dev = inputInfo.devices; dev; dev = dev->next) + { + if (dev->deviceGrab.grab) + for (i = 0; i < currentMaxClients; i++) { + if (clients[i] == NULL) + continue; + if (CLIENT_BITS(dev->deviceGrab.grab->resource) == + clients[i]->clientAsMask) { + ErrorF("Client holding device grab at VT switch:\n"); + kvetch_about_client(clients[i], dev); + } + } + } + } while (0); + } else { DebugF("xf86VTSwitch: Entering\n"); --- xorg-server-1.7.6.901/hw/xfree86/common/xf86Init.c 2010-04-09 14:23:31.000000000 +0200 +++ xorg-server-1.7.6.901-PATCHED/hw/xfree86/common/xf86Init.c 2010-04-27 12:35:15.000000000 +0200 @@ -552,6 +552,8 @@ xf86Initialising = TRUE; + DeleteCallback(&ServerGrabCallback, xf86GrabCallback, NULL); + if (serverGeneration == 1) { pScreenInfo->numScreens = 0; @@ -1095,6 +1097,7 @@ RegisterBlockAndWakeupHandlers((BlockHandlerProcPtr)NoopDDA, xf86Wakeup, NULL); + AddCallback(&ServerGrabCallback, xf86GrabCallback, NULL); } /* --- xorg-server-1.7.6.901/hw/xfree86/common/xf86Priv.h 2010-04-09 14:23:10.000000000 +0200 +++ xorg-server-1.7.6.901-PATCHED/hw/xfree86/common/xf86Priv.h 2010-04-27 12:35:15.000000000 +0200 @@ -146,6 +147,8 @@ extern _X_EXPORT int (*xf86PMGetEventFromOs)(int fd,pmEvent *events,int num); extern _X_EXPORT pmWait (*xf86PMConfirmEventToOs)(int fd,pmEvent event); +extern void xf86GrabCallback(CallbackListPtr *cbl, void *data, void *closure); + /* xf86Helper.c */ extern _X_EXPORT void xf86LogInit(void); extern _X_EXPORT void xf86CloseLog(void);