[PATCH] Include client name if available in PrintDeviceGrabInfo

Alan Coopersmith alan.coopersmith at oracle.com
Wed Dec 7 23:02:59 PST 2011


Also adds missing newline to first line of output.

Before patch:

[3581472.414] (II) Printing all currently active device grabs:
[3581472.414] Active grab 0x1800000 (core) on device 'Virtual core pointer' (2):
      client pid 26174 uid 0 gid 10
[3581472.415]       at 3581469139 (from active grab) (device thawed, state 1)
[3581472.415]         core event mask 0x0
[3581472.415]       owner-events true, kb 1 ptr 1, confine 0, cursor 0x0
[3581472.415] Active grab 0x1800000 (core) on device 'Virtual core keyboard' (3)
:      client pid 26174 uid 0 gid 10
[3581472.415]       at 3581469139 (from active grab) (device thawed, state 1)
[3581472.415]         core event mask 0x3
[3581472.415]       owner-events true, kb 1 ptr 1, confine 0, cursor 0x0
[3581472.415] (II) End list of active device grabs

After patch:
[3581736.601] (II) Printing all currently active device grabs:
[3581736.601] Active grab 0x1600000 (core) on device 'Virtual core pointer' (2):
[3581736.601]       client pid 26741 /usr/bin/xscreensaver -nosplash
[3581736.601]       at 3581735000 (from active grab) (device thawed, state 1)
[3581736.601]         core event mask 0x0
[3581736.601]       owner-events true, kb 1 ptr 1, confine 0, cursor 0x0
[3581736.601] Active grab 0x1600000 (core) on device 'Virtual core keyboard' (3)
:
[3581736.601]       client pid 26741 /usr/bin/xscreensaver -nosplash
[3581736.601]       at 3581735000 (from active grab) (device thawed, state 1)
[3581736.601]         core event mask 0x3
[3581736.601]       owner-events true, kb 1 ptr 1, confine 0, cursor 0x0
[3581736.601] (II) End list of active device grabs

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 dix/grabs.c |   35 ++++++++++++++++++++++++++---------
 1 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/dix/grabs.c b/dix/grabs.c
index c28356d..aeb3256 100644
--- a/dix/grabs.c
+++ b/dix/grabs.c
@@ -60,6 +60,7 @@ SOFTWARE.
 #include "dixgrabs.h"
 #include "xace.h"
 #include "exevents.h"
+#include "client.h"
 
 #define BITMASK(i) (((Mask)1) << ((i) & 31))
 #define MASKIDX(i) ((i) >> 5)
@@ -76,25 +77,41 @@ PrintDeviceGrabInfo(DeviceIntPtr dev)
     int i, j;
     GrabInfoPtr devGrab = &dev->deviceGrab;
     GrabPtr grab = devGrab->grab;
+    Bool clientIdPrinted = FALSE;
 
-    ErrorF("Active grab 0x%lx (%s) on device '%s' (%d):",
+    ErrorF("Active grab 0x%lx (%s) on device '%s' (%d):\n",
            (unsigned long) grab->resource,
            (grab->grabtype == GRABTYPE_XI2) ? "xi2" :
             ((grab->grabtype == GRABTYPE_CORE) ? "core" : "xi1"),
            dev->name, dev->id);
 
     client = clients[CLIENT_ID(grab->resource)];
-    if (client && GetLocalClientCreds(client, &lcc) != -1)
+    if (client)
     {
-        ErrorF("      client pid %ld uid %ld gid %ld\n",
-               (lcc->fieldsSet & LCC_PID_SET) ? (long) lcc->pid : 0,
-               (lcc->fieldsSet & LCC_UID_SET) ? (long) lcc->euid : 0,
-               (lcc->fieldsSet & LCC_GID_SET) ? (long) lcc->egid : 0);
-        FreeLocalClientCreds(lcc);
+        pid_t clientpid = GetClientPid(client);
+        const char *cmdname = GetClientCmdName(client);
+        const char *cmdargs = GetClientCmdArgs(client);
+
+        if ((clientpid > 0) && (cmdname != NULL))
+        {
+            ErrorF("      client pid %ld %s %s\n",
+                   clientpid, cmdname, cmdargs ? cmdargs : "");
+            clientIdPrinted = TRUE;
+        }
+        else if (GetLocalClientCreds(client, &lcc) != -1)
+        {
+            ErrorF("      client pid %ld uid %ld gid %ld\n",
+                   (lcc->fieldsSet & LCC_PID_SET) ? (long) lcc->pid : 0,
+                   (lcc->fieldsSet & LCC_UID_SET) ? (long) lcc->euid : 0,
+                   (lcc->fieldsSet & LCC_GID_SET) ? (long) lcc->egid : 0);
+            FreeLocalClientCreds(lcc);
+            clientIdPrinted = TRUE;
+        }
     }
-    else
+    if (!clientIdPrinted)
     {
-        ErrorF("      (no client information available)\n");
+        ErrorF("      (no client information available for client %d)\n",
+               CLIENT_ID(grab->resource));
     }
 
     /* XXX is this even correct? */
-- 
1.7.3.2



More information about the xorg-devel mailing list