X client's don't have a wl_client associated with their
weston_desktop_client, so make sure to not use it.

Signed-off-by: Giulio Camuffo <[email protected]>
---

v2: use -1 as the pid unset value, and initialize the pid to 0 for xwayland
    surfaces. This means the branch where we use the client is never reached
    for xwayland, even if the pid is not set.

 libweston-desktop/surface.c  | 8 +++++++-
 libweston-desktop/xwayland.c | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/libweston-desktop/surface.c b/libweston-desktop/surface.c
index 2205107..d3be936 100644
--- a/libweston-desktop/surface.c
+++ b/libweston-desktop/surface.c
@@ -269,6 +269,8 @@ weston_desktop_surface_create(struct weston_desktop 
*desktop,
        wsurface->committed = weston_desktop_surface_committed;
        wsurface->committed_private = surface;
 
+       surface->pid = -1;
+
        surface->surface_commit_listener.notify =
                weston_desktop_surface_surface_committed;
        wl_signal_add(&surface->surface->commit_signal,
@@ -590,7 +592,7 @@ weston_desktop_surface_get_pid(struct 
weston_desktop_surface *surface)
 {
        pid_t pid;
 
-       if (surface->pid != 0) {
+       if (surface->pid != -1) {
                pid = surface->pid;
        } else {
                struct weston_desktop_client *client =
@@ -598,6 +600,10 @@ weston_desktop_surface_get_pid(struct 
weston_desktop_surface *surface)
                struct wl_client *wl_client =
                        weston_desktop_client_get_client(client);
 
+               /* wl_client should always be valid, because only in the
+                * xwayland case it wouldn't be, but in that case we won't
+                * reach here, as the pid is initialized to 0. */
+               assert(wl_client);
                wl_client_get_credentials(wl_client, &pid, NULL, NULL);
        }
        return pid;
diff --git a/libweston-desktop/xwayland.c b/libweston-desktop/xwayland.c
index c89248c..0741a4c 100644
--- a/libweston-desktop/xwayland.c
+++ b/libweston-desktop/xwayland.c
@@ -241,6 +241,8 @@ create_surface(struct weston_desktop_xwayland *xwayland,
        wl_resource_add_destroy_listener(wsurface->resource,
                                         &surface->resource_destroy_listener);
 
+       weston_desktop_surface_set_pid(surface->surface, 0);
+
        return surface;
 }
 
-- 
2.10.2

_______________________________________________
wayland-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to