frontend: Add data argument to wet_process cleanup
wet_process provides a cleanup function which can be called, but only passes the process itself. This relies on the process struct being inlined in something else meaningful, and means that we can't allocate them on demand. Add a 'data' argument which allows users to pass meaningful data to their cleanup handler. Signed-off-by: Daniel Stone <daniels@collabora.com>
This commit is contained in:
parent
abe893d8ea
commit
c2cd15ed11
|
@ -362,7 +362,7 @@ sigchld_handler(int signal_number, void *data)
|
|||
wl_list_remove(&p->link);
|
||||
wl_list_init(&p->link);
|
||||
free(p->path);
|
||||
p->cleanup(p, status);
|
||||
p->cleanup(p, status, p->cleanup_data);
|
||||
}
|
||||
|
||||
if (pid < 0 && errno != ECHILD)
|
||||
|
@ -394,7 +394,8 @@ weston_client_launch(struct weston_compositor *compositor,
|
|||
struct custom_env *child_env,
|
||||
int *no_cloexec_fds,
|
||||
size_t num_no_cloexec_fds,
|
||||
wet_process_cleanup_func_t cleanup)
|
||||
wet_process_cleanup_func_t cleanup,
|
||||
void *cleanup_data)
|
||||
{
|
||||
struct wet_compositor *wet = to_wet_compositor(compositor);
|
||||
const char *fail_cloexec = "Couldn't unset CLOEXEC on child FDs";
|
||||
|
@ -445,6 +446,7 @@ weston_client_launch(struct weston_compositor *compositor,
|
|||
default:
|
||||
proc->pid = pid;
|
||||
proc->cleanup = cleanup;
|
||||
proc->cleanup_data = cleanup_data;
|
||||
proc->path = strdup(argp[0]);
|
||||
wl_list_insert(&wet->child_process_list, &proc->link);
|
||||
ret = true;
|
||||
|
@ -464,7 +466,7 @@ weston_client_launch(struct weston_compositor *compositor,
|
|||
}
|
||||
|
||||
static void
|
||||
process_handle_sigchld(struct wet_process *process, int status)
|
||||
process_handle_sigchld(struct wet_process *process, int status, void *data)
|
||||
{
|
||||
/*
|
||||
* There are no guarantees whether this runs before or after
|
||||
|
@ -519,7 +521,7 @@ wet_client_start(struct weston_compositor *compositor, const char *path)
|
|||
|
||||
ret = weston_client_launch(compositor, proc, &child_env,
|
||||
no_cloexec_fds, num_no_cloexec_fds,
|
||||
process_handle_sigchld);
|
||||
process_handle_sigchld, NULL);
|
||||
if (!ret)
|
||||
goto err;
|
||||
|
||||
|
|
|
@ -38,12 +38,14 @@ screenshooter_create(struct weston_compositor *ec);
|
|||
|
||||
struct wet_process;
|
||||
typedef void (*wet_process_cleanup_func_t)(struct wet_process *process,
|
||||
int status);
|
||||
int status,
|
||||
void *data);
|
||||
|
||||
struct wet_process {
|
||||
pid_t pid;
|
||||
char *path;
|
||||
wet_process_cleanup_func_t cleanup;
|
||||
void *cleanup_data;
|
||||
struct wl_list link;
|
||||
};
|
||||
|
||||
|
@ -55,7 +57,8 @@ weston_client_launch(struct weston_compositor *compositor,
|
|||
struct custom_env *custom_env,
|
||||
int *fds_no_cloexec,
|
||||
size_t num_fds_no_cloexec,
|
||||
wet_process_cleanup_func_t cleanup);
|
||||
wet_process_cleanup_func_t cleanup,
|
||||
void *cleanup_data);
|
||||
|
||||
struct wl_client *
|
||||
wet_client_start(struct weston_compositor *compositor, const char *path);
|
||||
|
|
|
@ -92,10 +92,9 @@ out:
|
|||
}
|
||||
|
||||
static void
|
||||
xserver_cleanup(struct wet_process *process, int status)
|
||||
xserver_cleanup(struct wet_process *process, int status, void *data)
|
||||
{
|
||||
struct wet_xwayland *wxw =
|
||||
container_of(process, struct wet_xwayland, process);
|
||||
struct wet_xwayland *wxw = data;
|
||||
|
||||
wxw->api->xserver_exited(wxw->xwayland, status);
|
||||
wxw->client = NULL;
|
||||
|
@ -170,7 +169,7 @@ spawn_xserver(void *user_data, const char *display, int abstract_fd, int unix_fd
|
|||
|
||||
ret = weston_client_launch(wxw->compositor, &wxw->process, &child_env,
|
||||
no_cloexec_fds, num_no_cloexec_fds,
|
||||
xserver_cleanup);
|
||||
xserver_cleanup, wxw);
|
||||
if (!ret) {
|
||||
weston_log("Couldn't start Xwayland\n");
|
||||
goto err;
|
||||
|
|
Loading…
Reference in New Issue