xwayland: Only pass Xwayland wl_client to libweston

Remove all handling of process/PID internals from libweston's Xwayland
launcher, and keep this only in the frontend. libweston now only sees
the wl_client and nothing else.

Signed-off-by: Daniel Stone <daniels@collabora.com>
This commit is contained in:
Daniel Stone 2023-05-01 15:54:52 +01:00
parent d5bcc26078
commit e64232a808
4 changed files with 18 additions and 27 deletions

View file

@ -52,7 +52,6 @@ struct wet_xwayland {
const struct weston_xwayland_api *api;
struct weston_xwayland *xwayland;
struct wl_event_source *display_fd_source;
struct wl_client *client;
int wm_fd;
struct wet_process *process;
};
@ -82,7 +81,7 @@ handle_display_fd(int fd, uint32_t mask, void *data)
if (n <= 0 || (n > 0 && buf[n - 1] != '\n'))
return 1;
wxw->api->xserver_loaded(wxw->xwayland, wxw->client, wxw->wm_fd);
wxw->api->xserver_loaded(wxw->xwayland, wxw->wm_fd);
out:
wl_event_source_remove(wxw->display_fd_source);
@ -101,11 +100,10 @@ xserver_cleanup(struct wet_process *process, int status, void *data)
assert(process == wxw->process);
wxw->api->xserver_exited(wxw->xwayland, status);
wxw->client = NULL;
wxw->process = NULL;
}
static pid_t
static struct wl_client *
spawn_xserver(void *user_data, const char *display, int abstract_fd, int unix_fd)
{
struct wet_xwayland *wxw = user_data;
@ -117,6 +115,7 @@ spawn_xserver(void *user_data, const char *display, int abstract_fd, int unix_fd
char *xserver = NULL;
struct weston_config *config = wet_get_config(wxw->compositor);
struct weston_config_section *section;
struct wl_client *client;
struct wl_event_loop *loop;
struct custom_env child_env;
int no_cloexec_fds[5];
@ -180,9 +179,9 @@ spawn_xserver(void *user_data, const char *display, int abstract_fd, int unix_fd
goto err;
}
wxw->client = wl_client_create(wxw->compositor->wl_display,
wayland_socket.fds[0]);
if (!wxw->client) {
client = wl_client_create(wxw->compositor->wl_display,
wayland_socket.fds[0]);
if (!client) {
weston_log("Couldn't create client for Xwayland\n");
goto err_proc;
}
@ -206,7 +205,7 @@ spawn_xserver(void *user_data, const char *display, int abstract_fd, int unix_fd
free(xserver);
return wxw->process->pid;
return client;
err_proc:
@ -217,7 +216,7 @@ err:
fdstr_close_all(&x11_wm_socket);
fdstr_close_all(&wayland_socket);
free(wxw->process);
return -1;
return NULL;
}
static void

View file

@ -37,10 +37,10 @@ extern "C" {
struct weston_compositor;
struct weston_xwayland;
#define WESTON_XWAYLAND_API_NAME "weston_xwayland_v1"
#define WESTON_XWAYLAND_API_NAME "weston_xwayland_v2"
#define WESTON_XWAYLAND_SURFACE_API_NAME "weston_xwayland_surface_v1"
typedef pid_t
typedef struct wl_client *
(*weston_xwayland_spawn_xserver_func_t)(
void *user_data, const char *display, int abstract_fd, int unix_fd);
@ -83,19 +83,16 @@ struct weston_xwayland_api {
/** Notify the Xwayland module that the Xwayland server is loaded.
*
* After the Xwayland server process has been spawned it will notify
* the parent that is has finished the initialization by sending a
* SIGUSR1 signal.
* The caller should listen for that signal and call this function
* the parent that it has finished the initialization by writing to
* the displayfd passed.
* The caller should listen for that write and call this function
* when it is received.
*
* \param xwayland The Xwayland context object.
* \param client The wl_client object representing the connection of
* the Xwayland server process.
* \param wm_fd The file descriptor for the wm.
*/
void
(*xserver_loaded)(struct weston_xwayland *xwayland,
struct wl_client *client, int wm_fd);
(*xserver_loaded)(struct weston_xwayland *xwayland, int wm_fd);
/** Notify the Xwayland module that the Xwayland server has exited.
*

View file

@ -49,13 +49,12 @@ weston_xserver_handle_event(int listen_fd, uint32_t mask, void *data)
snprintf(display, sizeof display, ":%d", wxs->display);
wxs->pid = wxs->spawn_func(wxs->user_data, display, wxs->abstract_fd, wxs->unix_fd);
if (wxs->pid == -1) {
wxs->client = wxs->spawn_func(wxs->user_data, display, wxs->abstract_fd, wxs->unix_fd);
if (wxs->client == NULL) {
weston_log("Failed to spawn the Xwayland server\n");
return 1;
}
weston_log("Spawned Xwayland server, pid %d\n", wxs->pid);
wl_event_source_remove(wxs->abstract_source);
wl_event_source_remove(wxs->unix_source);
@ -71,7 +70,7 @@ weston_xserver_shutdown(struct weston_xserver *wxs)
unlink(path);
snprintf(path, sizeof path, "/tmp/.X11-unix/X%d", wxs->display);
unlink(path);
if (wxs->pid == 0) {
if (wxs->client == NULL) {
wl_event_source_remove(wxs->abstract_source);
wl_event_source_remove(wxs->unix_source);
}
@ -305,12 +304,10 @@ retry:
}
static void
weston_xwayland_xserver_loaded(struct weston_xwayland *xwayland,
struct wl_client *client, int wm_fd)
weston_xwayland_xserver_loaded(struct weston_xwayland *xwayland, int wm_fd)
{
struct weston_xserver *wxs = (struct weston_xserver *)xwayland;
wxs->wm = weston_wm_create(wxs, wm_fd);
wxs->client = client;
}
static void
@ -319,7 +316,6 @@ weston_xwayland_xserver_exited(struct weston_xwayland *xwayland,
{
struct weston_xserver *wxs = (struct weston_xserver *)xwayland;
wxs->pid = 0;
wxs->client = NULL;
wxs->abstract_source =

View file

@ -43,7 +43,6 @@ struct weston_xserver {
int unix_fd;
struct wl_event_source *unix_source;
int display;
pid_t pid;
struct wl_client *client;
struct weston_compositor *compositor;
struct weston_wm *wm;