RFC: automatic _NET_WM_PID setting for local clients

xorg at pengaru.com xorg at pengaru.com
Tue Jul 23 20:57:01 UTC 2019


Hello folks,

I'd like to propose that Xorg set the _NET_WM_PID property on new
windows for local clients @ window create time whenever possible.  

This is something I added localy years ago to more reliably have this
property set with uncooperative clients that didn't set it.  My window
manager integrates client process monitoring and relies on this property
for acquiring the PID of connected clients.

At the time, it was just a few X clients that were problematic, stuff
like xpdf and other smaller programs using less popular toolkits or no
toolkit at all.  It wasn't such a big deal, so I promptly forgot about
it and stopped building my own Xorg debs with the patch, living with the
absent monitoring overlays on those windows.

Fast-forward to today; I'm using systemd-nspawn for running X clients -
particularly network-facing clients like FireFox where I _strongly_
prefer isolating the client from accessing things like my home directory
for obvious reasons (ssh keys, etc).

These programs are cooperative and set _NET_WM_PID, but the PID they set
is from the perspective of the container namespace.  The display server
is running in the global host namespace, where this PID has zero
relevance.  The same goes for my window manager, it to runs in the
host's namespace, so when it gets this PID and tries to monitor the
process subtree rooted at that PID in /proc, it either finds nothing or
the entirely wrong tree.

So again I'm wishing the display server would just set this property for
local clients immediately when creating the window, which would not only
make the property more reliable but now it would also set it from the
PIDNS of the Xorg server, that I would argue is far more meaningful.

I happened to still have the old patch I was using to do this back in
the day, and have attached it as-is for discussion purposes.

Thanks,
Vito Caputo
-------------- next part --------------
--- xorg-server-1.12.4/dix/window.c	2012-05-17 10:09:02.000000000 -0700
+++ xorg-server-1.12.4.hacked/dix/window.c	2014-06-04 18:54:33.570855708 -0700
@@ -840,6 +840,20 @@
         event.u.createNotify.override = pWin->overrideRedirect;
         DeliverEvents(pParent, &event, 1, NullWindow);
     }
+
+    if (pScreen->root == pParent) {
+        /* top-level windows with local connections can reliably get _NET_WM_PID set by the server */
+        LocalClientCredRec *lcc;
+        if (GetLocalClientCreds(client, &lcc) != -1)
+            if (lcc->fieldsSet & LCC_PID_SET) {
+                Atom prop;
+
+                prop = MakeAtom("_NET_WM_PID", strlen("_NET_WM_PID"), TRUE);
+                dixChangeWindowProperty(client, pWin, prop,
+                                        XA_CARDINAL, 32, PropModeReplace,
+                                        1, &lcc->pid, FALSE);
+            }
+    }
     return pWin;
 }
 


More information about the xorg-devel mailing list