Skip to content

Commit

Permalink
replace _NET_WM_PID with XResGetClientPid (#741)
Browse files Browse the repository at this point in the history
window-props: use XResQueryClientIds to get pid

_NET_WM_PID is unreliable! It can be faked or pid might be from
different namespace. Ignore _NET_WM_PID and use XResQueryClientIds
to get pid.

https://gitlab.gnome.org/GNOME/metacity/-/commit/bcbe966511362a8eb8c8c64035ab160086c931f8
  • Loading branch information
lambdanil committed Nov 7, 2022
1 parent db228e2 commit 2540175
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .build.yml
Expand Up @@ -14,6 +14,7 @@ requires:
- libcanberra
- libgtop
- libxpresent
- libxres
- make
- mate-common
- mate-desktop
Expand Down Expand Up @@ -51,6 +52,7 @@ requires:
- libxpresent-dev
- libxrandr-dev
- libxrender-dev
- libxres-dev
- libxt-dev
- make
- mate-common
Expand All @@ -72,6 +74,7 @@ requires:
- libSM-devel
- libXdamage-devel
- libXpresent-devel
- libXres-devel
- libcanberra-devel
- libgtop2-devel
- libsoup-devel
Expand Down Expand Up @@ -110,6 +113,7 @@ requires:
- libxpresent-dev
- libxrandr-dev
- libxrender-dev
- libxres-dev
- libxt-dev
- make
- mate-common
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -164,7 +164,7 @@ if test x$have_xcomposite = xyes; then
fi

if test x$have_xcomposite = xyes; then
MARCO_PC_MODULES="$MARCO_PC_MODULES xcomposite >= $XCOMPOSITE_VERSION xfixes xrender xdamage"
MARCO_PC_MODULES="$MARCO_PC_MODULES xcomposite >= $XCOMPOSITE_VERSION xfixes xrender xdamage xres"
AC_DEFINE(HAVE_COMPOSITE_EXTENSIONS, 1, [Building with compositing manager support])
echo "Building with compositing manager"

Expand Down
3 changes: 3 additions & 0 deletions meson.build
Expand Up @@ -153,12 +153,14 @@ gtk_req = '>= 3.22.0'
pango_req = '>= 1.2.0'
libcanberra_gtk_req = '>= 3.22.0'
startup_notification_req = '>= 0.7'
xres_req = '>= 1.2.0'

glib_dep = dependency('glib-2.0', version: glib_req)
gtk_dep = dependency('gtk+-3.0', version: gtk_req)
gio_dep = dependency('gio-2.0', version: gio_req)
pango_dep = dependency('pango', version: pango_req)
libcanberra_gtk_dep = dependency('libcanberra-gtk3')
xres_dep = dependency('xres', version: xres_req)
x11_dep = dependency('x11')

marco_deps = [
Expand All @@ -167,6 +169,7 @@ marco_deps = [
gio_dep,
pango_dep,
libcanberra_gtk_dep,
xres_dep,
]

marco_message_deps = [
Expand Down
46 changes: 46 additions & 0 deletions src/core/window-props.c
Expand Up @@ -47,6 +47,7 @@
#include "frame-private.h"
#include "group.h"
#include <X11/Xatom.h>
#include <X11/extensions/XRes.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
Expand Down Expand Up @@ -294,11 +295,56 @@ reload_wm_window_role (MetaWindow *window,
meta_window_update_role (window);
}

static pid_t
get_local_pid (MetaWindow *window)
{
pid_t pid;
XResClientIdSpec spec;
long num_ids;
XResClientIdValue *client_ids;
long i;

pid = -1;

spec.client = window->xwindow;
spec.mask = XRES_CLIENT_ID_PID_MASK;

XResQueryClientIds (window->display->xdisplay,
1,
&spec,
&num_ids,
&client_ids);

for (i = 0; i < num_ids; i++)
{
if (client_ids[i].spec.mask == XRES_CLIENT_ID_PID_MASK)
{
pid = XResGetClientPid (&client_ids[i]);
break;
}
}

XResClientIdsDestroy (num_ids, client_ids);

return pid;
}

static void
reload_net_wm_pid (MetaWindow *window,
MetaPropValue *value,
gboolean initial)
{
pid_t pid;

pid = get_local_pid (window);

if (pid != -1)
{
meta_verbose ("Using XResGetClientPid instead of _NET_WM_PID\n");

window->net_wm_pid = pid;
return;
}
if (value->type != META_PROP_VALUE_INVALID)
{
gulong cardinal = (int) value->v.cardinal;
Expand Down

0 comments on commit 2540175

Please sign in to comment.