[PATCH weston] xdg-shell: Add NULL checks for resources that may have gone away.

2016-12-03 Thread Dima Ryazanov
This should fix some (fairly rare) crashes where the client goes away at exactly
the wrong moment, e.g.:
- Weston sends a message to the client
- Message causes the client to crash for whatever reason
- Weston keeps processing the remaining requests from the now dead client

(I've only seen it happen once, while stepping through Weston's code in gdb, but
seems like the right thing to fix.)

Signed-off-by: Dima Ryazanov 
---
 libweston-desktop/xdg-shell-v6.c | 141 ---
 1 file changed, 101 insertions(+), 40 deletions(-)

diff --git a/libweston-desktop/xdg-shell-v6.c b/libweston-desktop/xdg-shell-v6.c
index 7d0bd8e..30f6d82 100644
--- a/libweston-desktop/xdg-shell-v6.c
+++ b/libweston-desktop/xdg-shell-v6.c
@@ -302,10 +302,14 @@ weston_desktop_xdg_toplevel_protocol_set_parent(struct 
wl_client *wl_client,
 {
struct weston_desktop_surface *dsurface =
wl_resource_get_user_data(resource);
-   struct weston_desktop_xdg_toplevel *toplevel =
-   weston_desktop_surface_get_implementation_data(dsurface);
+   struct weston_desktop_xdg_toplevel *toplevel;
struct weston_desktop_surface *parent = NULL;
 
+   if (!dsurface)
+   return;
+
+   toplevel = weston_desktop_surface_get_implementation_data(dsurface);
+
if (parent_resource != NULL)
parent = wl_resource_get_user_data(parent_resource);
 
@@ -346,8 +350,12 @@ 
weston_desktop_xdg_toplevel_protocol_show_window_menu(struct wl_client *wl_clien
wl_resource_get_user_data(resource);
struct weston_seat *seat =
wl_resource_get_user_data(seat_resource);
-   struct weston_desktop_xdg_toplevel *toplevel =
-   weston_desktop_surface_get_implementation_data(dsurface);
+   struct weston_desktop_xdg_toplevel *toplevel;
+
+   if (!dsurface)
+   return;
+
+   toplevel = weston_desktop_surface_get_implementation_data(dsurface);
 
if (!toplevel->base.configured) {
wl_resource_post_error(toplevel->resource,
@@ -370,8 +378,12 @@ weston_desktop_xdg_toplevel_protocol_move(struct wl_client 
*wl_client,
wl_resource_get_user_data(resource);
struct weston_seat *seat =
wl_resource_get_user_data(seat_resource);
-   struct weston_desktop_xdg_toplevel *toplevel =
-   weston_desktop_surface_get_implementation_data(dsurface);
+   struct weston_desktop_xdg_toplevel *toplevel;
+
+   if (!dsurface)
+   return;
+
+   toplevel = weston_desktop_surface_get_implementation_data(dsurface);
 
if (!toplevel->base.configured) {
wl_resource_post_error(toplevel->resource,
@@ -394,11 +406,15 @@ weston_desktop_xdg_toplevel_protocol_resize(struct 
wl_client *wl_client,
wl_resource_get_user_data(resource);
struct weston_seat *seat =
wl_resource_get_user_data(seat_resource);
-   struct weston_desktop_xdg_toplevel *toplevel =
-   weston_desktop_surface_get_implementation_data(dsurface);
+   struct weston_desktop_xdg_toplevel *toplevel;
enum weston_desktop_surface_edge surf_edges =
(enum weston_desktop_surface_edge) edges;
 
+   if (!dsurface)
+   return;
+
+   toplevel = weston_desktop_surface_get_implementation_data(dsurface);
+
if (!toplevel->base.configured) {
wl_resource_post_error(toplevel->resource,
   ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
@@ -423,9 +439,12 @@ weston_desktop_xdg_toplevel_protocol_set_min_size(struct 
wl_client *wl_client,
 {
struct weston_desktop_surface *dsurface =
wl_resource_get_user_data(resource);
-   struct weston_desktop_xdg_toplevel *toplevel =
-   weston_desktop_surface_get_implementation_data(dsurface);
+   struct weston_desktop_xdg_toplevel *toplevel;
 
+   if (!dsurface)
+   return;
+
+   toplevel = weston_desktop_surface_get_implementation_data(dsurface);
toplevel->next_min_size.width = width;
toplevel->next_min_size.height = height;
 }
@@ -437,9 +456,12 @@ weston_desktop_xdg_toplevel_protocol_set_max_size(struct 
wl_client *wl_client,
 {
struct weston_desktop_surface *dsurface =
wl_resource_get_user_data(resource);
-   struct weston_desktop_xdg_toplevel *toplevel =
-   weston_desktop_surface_get_implementation_data(dsurface);
+   struct weston_desktop_xdg_toplevel *toplevel;
+
+   if (!dsurface)
+   return;
 
+   toplevel = weston_desktop_surface_get_implementation_data(dsurface);
toplevel->next_max_size.width = width;
toplevel->next_max_size.height = height;
 }
@@ -450,9 +472,12 @@ weston_desktop_xdg_toplevel_protocol_set_maximized(struct 
wl_client *wl_client,
 {
struct weston_desktop_surface *dsurface =
 

Re: Recommended dev setup?

2016-12-03 Thread Yong Bakos
Hi David,

> On Dec 2, 2016, at 7:48 PM, David Piper  wrote:
> 
> Hi all,
> 
> I'm jumping back into the Wayland loop after more than a year. My first port 
> of call is once again building Wayland and Weston and getting some of the 
> sample clients running. About all I've done so far is install Weston the 
> quick and dirty (apt-get) way on Ubuntu and read through the build 
> instructions.
> 
> Next I'd like to follow the build instructions, get some of the sample 
> clients running and then start writing my own toy clients. Once I've done 
> that I wouldn't mind hacking a bit on the weston compositor - probably not 
> touching libweston itself, but at least getting to know it.
> 
> I'll be pushing along in Ubuntu for now but I thought I should throw the 
> question out here - what is the best dev loop for working with Wayland? 
> Should I be using Ubuntu or should I look for an OS that supports Wayland out 
> of the box? What kind of environment setup would make things faster?

Any major distro will be fine. Folks use Ubuntu, Fedora, etc.
You do not need to run a DE that uses Wayland in order to
build & run Wayland/Weston.

yong


> 
> Cheers,
> 
> David
> 
> ___
> wayland-devel mailing list
> wayland-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/wayland-devel

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel