Skip to content

Commit

Permalink
libweston-desktop: don't crash when getting the pid for X clients
Browse files Browse the repository at this point in the history
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]>
Reviewed-by: Quentin Glidic <[email protected]>
  • Loading branch information
giucam authored and sardemff7 committed Dec 8, 2016
1 parent 2295a62 commit f15320f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion libweston-desktop/surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -590,14 +592,18 @@ 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 =
weston_desktop_surface_get_client(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;
Expand Down
2 changes: 2 additions & 0 deletions libweston-desktop/xwayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit f15320f

Please sign in to comment.