]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Fix pid lookup for the Kill action
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Mon, 22 Apr 2024 15:43:46 +0000 (17:43 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Mon, 22 Apr 2024 18:11:57 +0000 (19:11 +0100)
Before this patch, labwc would happily kill itself when the user
called the `Kill` action when any xwayland view had focus.

The reason this happened was that wlroots creates the xwayland
wayland client via socketpair() and thus a lookup of the pid
of the socket connection would return the pid of labwc itself.

This patch fixes that by implementing different pid lookup
mechanisms based on the view implementation backend.

Fixes: #1739
include/view.h
src/action.c
src/xdg.c
src/xwayland.c

index 0cc3cfbdadd404f874a5236711334874bd55593c..182a28b897ead941dfde116beaa00427cba89c39 100644 (file)
@@ -135,6 +135,8 @@ struct view_impl {
        bool (*has_strut_partial)(struct view *self);
        /* returns true if view declared itself a window type */
        bool (*contains_window_type)(struct view *view, int32_t window_type);
+       /* returns the client pid that this view belongs to */
+       pid_t (*get_pid)(struct view *view);
 };
 
 struct view {
index 7cc4bc56bcea19c8bd9788e6a8041bf0ed84360f..bf94e0a0baba65ac31aca9d758adcd02f773ba09 100644 (file)
@@ -691,12 +691,13 @@ actions_run(struct view *activator, struct server *server,
                        }
                        break;
                case ACTION_TYPE_KILL:
-                       if (view && view->surface) {
+                       if (view) {
                                /* Send SIGTERM to the process associated with the surface */
-                               pid_t pid = -1;
-                               struct wl_client *client = view->surface->resource->client;
-                               wl_client_get_credentials(client, &pid, NULL, NULL);
-                               if (pid != -1) {
+                               assert(view->impl->get_pid);
+                               pid_t pid = view->impl->get_pid(view);
+                               if (pid == getpid()) {
+                                       wlr_log(WLR_ERROR, "Preventing sending SIGTERM to labwc");
+                               } else if (pid > 0) {
                                        kill(pid, SIGTERM);
                                }
                        }
index 154eb34f66518b43fee277199d14b8b5496d8764..78c549b025f2babbaf194bf39fe4f3a915a4b23d 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -659,6 +659,20 @@ xdg_toplevel_view_unmap(struct view *view, bool client_request)
        }
 }
 
+static pid_t
+xdg_view_get_pid(struct view *view)
+{
+       assert(view);
+       pid_t pid = -1;
+
+       if (view->surface && view->surface->resource
+                       && view->surface->resource->client) {
+               struct wl_client *client = view->surface->resource->client;
+               wl_client_get_credentials(client, &pid, NULL, NULL);
+       }
+       return pid;
+}
+
 static const struct view_impl xdg_toplevel_view_impl = {
        .configure = xdg_toplevel_view_configure,
        .close = xdg_toplevel_view_close,
@@ -675,6 +689,7 @@ static const struct view_impl xdg_toplevel_view_impl = {
        .get_root = xdg_toplevel_view_get_root,
        .append_children = xdg_toplevel_view_append_children,
        .contains_window_type = xdg_toplevel_view_contains_window_type,
+       .get_pid = xdg_view_get_pid,
 };
 
 static void
index 58d61a8076f77a9713cb856cb1957c32d8cb773d..3a936456fc2355cc7512f6d33094b48ef3813c5c 100644 (file)
@@ -838,6 +838,19 @@ xwayland_view_set_fullscreen(struct view *view, bool fullscreen)
                fullscreen);
 }
 
+static pid_t
+xwayland_view_get_pid(struct view *view)
+{
+       assert(view);
+
+       struct wlr_xwayland_surface *xwayland_surface =
+               xwayland_surface_from_view(view);
+       if (!xwayland_surface) {
+               return -1;
+       }
+       return xwayland_surface->pid;
+}
+
 static const struct view_impl xwayland_view_impl = {
        .configure = xwayland_view_configure,
        .close = xwayland_view_close,
@@ -856,6 +869,7 @@ static const struct view_impl xwayland_view_impl = {
        .wants_focus = xwayland_view_wants_focus,
        .has_strut_partial = xwayland_view_has_strut_partial,
        .contains_window_type = xwayland_view_contains_window_type,
+       .get_pid = xwayland_view_get_pid,
 };
 
 void