Move the functions launching clients to main.c
They belong in the compositor rather than libweston since they set signals handlers, and a library should not do that behind its user's back. Besides, they were using functions in main.c already so they were not usable by other compositors. Signed-off-by: Giulio Camuffo <giuliocamuffo@gmail.com> Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
committed by
Pekka Paalanen
parent
26f62d4247
commit
fba27fbef2
@@ -62,6 +62,7 @@
|
|||||||
#include "ivi-hmi-controller-server-protocol.h"
|
#include "ivi-hmi-controller-server-protocol.h"
|
||||||
#include "shared/helpers.h"
|
#include "shared/helpers.h"
|
||||||
#include "shared/xalloc.h"
|
#include "shared/xalloc.h"
|
||||||
|
#include "src/weston.h"
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* structure, globals
|
* structure, globals
|
||||||
|
|||||||
@@ -235,150 +235,6 @@ weston_output_mode_switch_to_temporary(struct weston_output *output,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
child_client_exec(int sockfd, const char *path)
|
|
||||||
{
|
|
||||||
int clientfd;
|
|
||||||
char s[32];
|
|
||||||
sigset_t allsigs;
|
|
||||||
|
|
||||||
/* do not give our signal mask to the new process */
|
|
||||||
sigfillset(&allsigs);
|
|
||||||
sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
|
|
||||||
|
|
||||||
/* Launch clients as the user. Do not lauch clients with wrong euid.*/
|
|
||||||
if (seteuid(getuid()) == -1) {
|
|
||||||
weston_log("compositor: failed seteuid\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* SOCK_CLOEXEC closes both ends, so we dup the fd to get a
|
|
||||||
* non-CLOEXEC fd to pass through exec. */
|
|
||||||
clientfd = dup(sockfd);
|
|
||||||
if (clientfd == -1) {
|
|
||||||
weston_log("compositor: dup failed: %m\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(s, sizeof s, "%d", clientfd);
|
|
||||||
setenv("WAYLAND_SOCKET", s, 1);
|
|
||||||
|
|
||||||
if (execl(path, path, NULL) < 0)
|
|
||||||
weston_log("compositor: executing '%s' failed: %m\n",
|
|
||||||
path);
|
|
||||||
}
|
|
||||||
|
|
||||||
WL_EXPORT struct wl_client *
|
|
||||||
weston_client_launch(struct weston_compositor *compositor,
|
|
||||||
struct weston_process *proc,
|
|
||||||
const char *path,
|
|
||||||
weston_process_cleanup_func_t cleanup)
|
|
||||||
{
|
|
||||||
int sv[2];
|
|
||||||
pid_t pid;
|
|
||||||
struct wl_client *client;
|
|
||||||
|
|
||||||
weston_log("launching '%s'\n", path);
|
|
||||||
|
|
||||||
if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sv) < 0) {
|
|
||||||
weston_log("weston_client_launch: "
|
|
||||||
"socketpair failed while launching '%s': %m\n",
|
|
||||||
path);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pid = fork();
|
|
||||||
if (pid == -1) {
|
|
||||||
close(sv[0]);
|
|
||||||
close(sv[1]);
|
|
||||||
weston_log("weston_client_launch: "
|
|
||||||
"fork failed while launching '%s': %m\n", path);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pid == 0) {
|
|
||||||
child_client_exec(sv[1], path);
|
|
||||||
_exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
close(sv[1]);
|
|
||||||
|
|
||||||
client = wl_client_create(compositor->wl_display, sv[0]);
|
|
||||||
if (!client) {
|
|
||||||
close(sv[0]);
|
|
||||||
weston_log("weston_client_launch: "
|
|
||||||
"wl_client_create failed while launching '%s'.\n",
|
|
||||||
path);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
proc->pid = pid;
|
|
||||||
proc->cleanup = cleanup;
|
|
||||||
weston_watch_process(proc);
|
|
||||||
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct process_info {
|
|
||||||
struct weston_process proc;
|
|
||||||
char *path;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
process_handle_sigchld(struct weston_process *process, int status)
|
|
||||||
{
|
|
||||||
struct process_info *pinfo =
|
|
||||||
container_of(process, struct process_info, proc);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* There are no guarantees whether this runs before or after
|
|
||||||
* the wl_client destructor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (WIFEXITED(status)) {
|
|
||||||
weston_log("%s exited with status %d\n", pinfo->path,
|
|
||||||
WEXITSTATUS(status));
|
|
||||||
} else if (WIFSIGNALED(status)) {
|
|
||||||
weston_log("%s died on signal %d\n", pinfo->path,
|
|
||||||
WTERMSIG(status));
|
|
||||||
} else {
|
|
||||||
weston_log("%s disappeared\n", pinfo->path);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(pinfo->path);
|
|
||||||
free(pinfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
WL_EXPORT struct wl_client *
|
|
||||||
weston_client_start(struct weston_compositor *compositor, const char *path)
|
|
||||||
{
|
|
||||||
struct process_info *pinfo;
|
|
||||||
struct wl_client *client;
|
|
||||||
|
|
||||||
pinfo = zalloc(sizeof *pinfo);
|
|
||||||
if (!pinfo)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
pinfo->path = strdup(path);
|
|
||||||
if (!pinfo->path)
|
|
||||||
goto out_free;
|
|
||||||
|
|
||||||
client = weston_client_launch(compositor, &pinfo->proc, path,
|
|
||||||
process_handle_sigchld);
|
|
||||||
if (!client)
|
|
||||||
goto out_str;
|
|
||||||
|
|
||||||
return client;
|
|
||||||
|
|
||||||
out_str:
|
|
||||||
free(pinfo->path);
|
|
||||||
|
|
||||||
out_free:
|
|
||||||
free(pinfo);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
region_init_infinite(pixman_region32_t *region)
|
region_init_infinite(pixman_region32_t *region)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1605,28 +1605,6 @@ text_backend_init(struct weston_compositor *ec);
|
|||||||
void
|
void
|
||||||
text_backend_destroy(struct text_backend *text_backend);
|
text_backend_destroy(struct text_backend *text_backend);
|
||||||
|
|
||||||
struct weston_process;
|
|
||||||
typedef void (*weston_process_cleanup_func_t)(struct weston_process *process,
|
|
||||||
int status);
|
|
||||||
|
|
||||||
struct weston_process {
|
|
||||||
pid_t pid;
|
|
||||||
weston_process_cleanup_func_t cleanup;
|
|
||||||
struct wl_list link;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct wl_client *
|
|
||||||
weston_client_launch(struct weston_compositor *compositor,
|
|
||||||
struct weston_process *proc,
|
|
||||||
const char *path,
|
|
||||||
weston_process_cleanup_func_t cleanup);
|
|
||||||
|
|
||||||
struct wl_client *
|
|
||||||
weston_client_start(struct weston_compositor *compositor, const char *path);
|
|
||||||
|
|
||||||
void
|
|
||||||
weston_watch_process(struct weston_process *process);
|
|
||||||
|
|
||||||
struct weston_view_animation;
|
struct weston_view_animation;
|
||||||
typedef void (*weston_view_animation_done_func_t)(struct weston_view_animation *animation, void *data);
|
typedef void (*weston_view_animation_done_func_t)(struct weston_view_animation *animation, void *data);
|
||||||
|
|
||||||
|
|||||||
+146
@@ -37,6 +37,7 @@
|
|||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
#ifdef HAVE_LIBUNWIND
|
#ifdef HAVE_LIBUNWIND
|
||||||
#define UNW_LOCAL_ONLY
|
#define UNW_LOCAL_ONLY
|
||||||
@@ -48,6 +49,7 @@
|
|||||||
#include "../shared/helpers.h"
|
#include "../shared/helpers.h"
|
||||||
#include "git-version.h"
|
#include "git-version.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
#include "weston.h"
|
||||||
|
|
||||||
#include "compositor-drm.h"
|
#include "compositor-drm.h"
|
||||||
#include "compositor-headless.h"
|
#include "compositor-headless.h"
|
||||||
@@ -168,12 +170,156 @@ print_backtrace(void)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void
|
||||||
|
child_client_exec(int sockfd, const char *path)
|
||||||
|
{
|
||||||
|
int clientfd;
|
||||||
|
char s[32];
|
||||||
|
sigset_t allsigs;
|
||||||
|
|
||||||
|
/* do not give our signal mask to the new process */
|
||||||
|
sigfillset(&allsigs);
|
||||||
|
sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
|
||||||
|
|
||||||
|
/* Launch clients as the user. Do not lauch clients with wrong euid.*/
|
||||||
|
if (seteuid(getuid()) == -1) {
|
||||||
|
weston_log("compositor: failed seteuid\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SOCK_CLOEXEC closes both ends, so we dup the fd to get a
|
||||||
|
* non-CLOEXEC fd to pass through exec. */
|
||||||
|
clientfd = dup(sockfd);
|
||||||
|
if (clientfd == -1) {
|
||||||
|
weston_log("compositor: dup failed: %m\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(s, sizeof s, "%d", clientfd);
|
||||||
|
setenv("WAYLAND_SOCKET", s, 1);
|
||||||
|
|
||||||
|
if (execl(path, path, NULL) < 0)
|
||||||
|
weston_log("compositor: executing '%s' failed: %m\n",
|
||||||
|
path);
|
||||||
|
}
|
||||||
|
|
||||||
|
WL_EXPORT struct wl_client *
|
||||||
|
weston_client_launch(struct weston_compositor *compositor,
|
||||||
|
struct weston_process *proc,
|
||||||
|
const char *path,
|
||||||
|
weston_process_cleanup_func_t cleanup)
|
||||||
|
{
|
||||||
|
int sv[2];
|
||||||
|
pid_t pid;
|
||||||
|
struct wl_client *client;
|
||||||
|
|
||||||
|
weston_log("launching '%s'\n", path);
|
||||||
|
|
||||||
|
if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sv) < 0) {
|
||||||
|
weston_log("weston_client_launch: "
|
||||||
|
"socketpair failed while launching '%s': %m\n",
|
||||||
|
path);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
if (pid == -1) {
|
||||||
|
close(sv[0]);
|
||||||
|
close(sv[1]);
|
||||||
|
weston_log("weston_client_launch: "
|
||||||
|
"fork failed while launching '%s': %m\n", path);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pid == 0) {
|
||||||
|
child_client_exec(sv[1], path);
|
||||||
|
_exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(sv[1]);
|
||||||
|
|
||||||
|
client = wl_client_create(compositor->wl_display, sv[0]);
|
||||||
|
if (!client) {
|
||||||
|
close(sv[0]);
|
||||||
|
weston_log("weston_client_launch: "
|
||||||
|
"wl_client_create failed while launching '%s'.\n",
|
||||||
|
path);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
proc->pid = pid;
|
||||||
|
proc->cleanup = cleanup;
|
||||||
|
weston_watch_process(proc);
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
WL_EXPORT void
|
WL_EXPORT void
|
||||||
weston_watch_process(struct weston_process *process)
|
weston_watch_process(struct weston_process *process)
|
||||||
{
|
{
|
||||||
wl_list_insert(&child_process_list, &process->link);
|
wl_list_insert(&child_process_list, &process->link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct process_info {
|
||||||
|
struct weston_process proc;
|
||||||
|
char *path;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
process_handle_sigchld(struct weston_process *process, int status)
|
||||||
|
{
|
||||||
|
struct process_info *pinfo =
|
||||||
|
container_of(process, struct process_info, proc);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* There are no guarantees whether this runs before or after
|
||||||
|
* the wl_client destructor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (WIFEXITED(status)) {
|
||||||
|
weston_log("%s exited with status %d\n", pinfo->path,
|
||||||
|
WEXITSTATUS(status));
|
||||||
|
} else if (WIFSIGNALED(status)) {
|
||||||
|
weston_log("%s died on signal %d\n", pinfo->path,
|
||||||
|
WTERMSIG(status));
|
||||||
|
} else {
|
||||||
|
weston_log("%s disappeared\n", pinfo->path);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(pinfo->path);
|
||||||
|
free(pinfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
WL_EXPORT struct wl_client *
|
||||||
|
weston_client_start(struct weston_compositor *compositor, const char *path)
|
||||||
|
{
|
||||||
|
struct process_info *pinfo;
|
||||||
|
struct wl_client *client;
|
||||||
|
|
||||||
|
pinfo = zalloc(sizeof *pinfo);
|
||||||
|
if (!pinfo)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
pinfo->path = strdup(path);
|
||||||
|
if (!pinfo->path)
|
||||||
|
goto out_free;
|
||||||
|
|
||||||
|
client = weston_client_launch(compositor, &pinfo->proc, path,
|
||||||
|
process_handle_sigchld);
|
||||||
|
if (!client)
|
||||||
|
goto out_str;
|
||||||
|
|
||||||
|
return client;
|
||||||
|
|
||||||
|
out_str:
|
||||||
|
free(pinfo->path);
|
||||||
|
|
||||||
|
out_free:
|
||||||
|
free(pinfo);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
log_uname(void)
|
log_uname(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "compositor.h"
|
#include "compositor.h"
|
||||||
|
#include "weston.h"
|
||||||
#include "text-input-unstable-v1-server-protocol.h"
|
#include "text-input-unstable-v1-server-protocol.h"
|
||||||
#include "input-method-unstable-v1-server-protocol.h"
|
#include "input-method-unstable-v1-server-protocol.h"
|
||||||
#include "shared/helpers.h"
|
#include "shared/helpers.h"
|
||||||
|
|||||||
@@ -35,6 +35,28 @@ extern "C" {
|
|||||||
void
|
void
|
||||||
screenshooter_create(struct weston_compositor *ec);
|
screenshooter_create(struct weston_compositor *ec);
|
||||||
|
|
||||||
|
struct weston_process;
|
||||||
|
typedef void (*weston_process_cleanup_func_t)(struct weston_process *process,
|
||||||
|
int status);
|
||||||
|
|
||||||
|
struct weston_process {
|
||||||
|
pid_t pid;
|
||||||
|
weston_process_cleanup_func_t cleanup;
|
||||||
|
struct wl_list link;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct wl_client *
|
||||||
|
weston_client_launch(struct weston_compositor *compositor,
|
||||||
|
struct weston_process *proc,
|
||||||
|
const char *path,
|
||||||
|
weston_process_cleanup_func_t cleanup);
|
||||||
|
|
||||||
|
struct wl_client *
|
||||||
|
weston_client_start(struct weston_compositor *compositor, const char *path);
|
||||||
|
|
||||||
|
void
|
||||||
|
weston_watch_process(struct weston_process *process);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "src/compositor.h"
|
#include "src/compositor.h"
|
||||||
|
#include "src/weston.h"
|
||||||
#include "weston-test-server-protocol.h"
|
#include "weston-test-server-protocol.h"
|
||||||
#include "ivi-test.h"
|
#include "ivi-test.h"
|
||||||
#include "ivi-shell/ivi-layout-export.h"
|
#include "ivi-shell/ivi-layout-export.h"
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "src/compositor.h"
|
#include "src/compositor.h"
|
||||||
|
#include "src/weston.h"
|
||||||
#include "weston-test-server-protocol.h"
|
#include "weston-test-server-protocol.h"
|
||||||
|
|
||||||
#ifdef ENABLE_EGL
|
#ifdef ENABLE_EGL
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include <cairo/cairo-xcb.h>
|
#include <cairo/cairo-xcb.h>
|
||||||
|
|
||||||
#include "compositor.h"
|
#include "compositor.h"
|
||||||
|
#include "weston.h"
|
||||||
|
|
||||||
#define SEND_EVENT_MASK (0x80)
|
#define SEND_EVENT_MASK (0x80)
|
||||||
#define EVENT_TYPE(event) ((event)->response_type & ~SEND_EVENT_MASK)
|
#define EVENT_TYPE(event) ((event)->response_type & ~SEND_EVENT_MASK)
|
||||||
|
|||||||
Reference in New Issue
Block a user