[libwnck] xutils: Get the correct PID for clients inside PID namespaces
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libwnck] xutils: Get the correct PID for clients inside PID namespaces
- Date: Tue, 29 Mar 2022 03:28:18 +0000 (UTC)
commit 07694559cc0c65ce1cca9ac33b165cef84c34d5e
Author: Ryan Gonzalez <ryan gonzalez collabora com>
Date: Fri Jan 7 17:14:43 2022 -0600
xutils: Get the correct PID for clients inside PID namespaces
This tries to use XResQueryClientIds to fetch the client's PID, which
will return the PID as seen by the host, rather than the PID as seen by
the client.
Signed-off-by: Ryan Gonzalez <ryan gonzalez collabora com>
libwnck/xutils.c | 36 +++++++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
---
diff --git a/libwnck/xutils.c b/libwnck/xutils.c
index e95abef8..9d0ee208 100644
--- a/libwnck/xutils.c
+++ b/libwnck/xutils.c
@@ -27,6 +27,9 @@
#if HAVE_CAIRO_XLIB_XRENDER
#include <cairo-xlib-xrender.h>
#endif
+#ifdef HAVE_XRES
+#include <X11/extensions/XRes.h>
+#endif
#include "screen.h"
#include "window.h"
#include "private.h"
@@ -1146,14 +1149,41 @@ int
_wnck_get_pid (Screen *screen,
Window xwindow)
{
- int val;
+ int pid = -1;
+
+#ifdef HAVE_XRES
+ XResClientIdSpec client_spec;
+ long client_id_count = 0;
+ XResClientIdValue *client_ids = NULL;
+
+ client_spec.client = xwindow;
+ client_spec.mask = XRES_CLIENT_ID_PID_MASK;
+
+ if (XResQueryClientIds (DisplayOfScreen (screen), 1, &client_spec,
+ &client_id_count, &client_ids) == Success)
+ {
+ long i;
+
+ for (i = 0; i < client_id_count; i++)
+ {
+ pid = XResGetClientPid (&client_ids[i]);
+ if (pid != -1)
+ break;
+ }
+
+ XResClientIdsDestroy (client_id_count, client_ids);
+
+ if (pid != -1)
+ return pid;
+ }
+#endif
if (!_wnck_get_cardinal (screen, xwindow,
_wnck_atom_get ("_NET_WM_PID"),
- &val))
+ &pid))
return 0;
else
- return val;
+ return pid;
}
char*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]