Fix pid lookup for the Kill action

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
This commit is contained in:
Consolatis 2024-04-22 17:43:46 +02:00 committed by Johan Malm
parent a109e6e3e8
commit 3f10857496
4 changed files with 37 additions and 5 deletions

View 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);
}
}