}
filename = udev_device_get_devnode(device);
- fd = weston_launcher_open(&ec->base, filename, O_RDWR);
+ fd = weston_launcher_open(ec->base.launcher, filename, O_RDWR);
if (fd < 0) {
/* Probably permissions error */
weston_log("couldn't open %s, skipping\n",
{
struct drm_compositor *d = (struct drm_compositor *) ec;
- if (weston_launcher_drm_set_master(&d->base, d->drm.fd, 0) < 0)
+ if (weston_launcher_drm_set_master(d->base.launcher, d->drm.fd, 0) < 0)
weston_log("failed to drop master: %m\n");
tty_reset(d->tty);
}
if (d->gbm)
gbm_device_destroy(d->gbm);
- if (weston_launcher_drm_set_master(&d->base, d->drm.fd, 0) < 0)
+ if (weston_launcher_drm_set_master(d->base.launcher, d->drm.fd, 0) < 0)
weston_log("failed to drop master: %m\n");
tty_destroy(d->tty);
case TTY_ENTER_VT:
weston_log("entering VT\n");
compositor->focus = 1;
- if (weston_launcher_drm_set_master(&ec->base, ec->drm.fd, 1)) {
+ if (weston_launcher_drm_set_master(ec->base.launcher,
+ ec->drm.fd, 1)) {
weston_log("failed to set master: %m\n");
wl_display_terminate(compositor->wl_display);
}
output->crtc_id, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0);
- if (weston_launcher_drm_set_master(&ec->base, ec->drm.fd, 0) < 0)
+ if (weston_launcher_drm_set_master(ec->base.launcher,
+ ec->drm.fd, 0) < 0)
weston_log("failed to drop master: %m\n");
break;
}
/* Check if we run drm-backend using weston-launch */
- ec->base.launcher_sock =
- weston_environment_get_fd("WESTON_LAUNCHER_SOCK");
- if (ec->base.launcher_sock == -1 && geteuid() != 0) {
+ ec->base.launcher = weston_launcher_connect(&ec->base);
+ if (ec->base.launcher == NULL && geteuid() != 0) {
weston_log("fatal: drm backend should be run "
"using weston-launch binary or as root\n");
goto err_compositor;
err_udev_dev:
udev_device_unref(drm_device);
err_tty:
- if (weston_launcher_drm_set_master(&ec->base, ec->drm.fd, 0) < 0)
+ if (weston_launcher_drm_set_master(ec->base.launcher,
+ ec->drm.fd, 0) < 0)
weston_log("failed to drop master: %m\n");
tty_destroy(ec->tty);
err_udev:
goto out_free;
/* Check if we run fbdev-backend using weston-launch */
- compositor->base.launcher_sock =
- weston_environment_get_fd("WESTON_LAUNCHER_SOCK");
- if (compositor->base.launcher_sock == -1 && geteuid() != 0) {
+ compositor->base.launcher = weston_launcher_connect(&compositor->base);
+ if (compositor->base.launcher == NULL && geteuid() != 0) {
weston_log("fatal: fbdev backend should be run "
"using weston-launch binary or as root\n");
goto out_compositor;
void (*ping_handler)(struct weston_surface *surface, uint32_t serial);
- int launcher_sock;
+ struct weston_launcher *launcher;
uint32_t output_id_pool;
/*
* Copyright © 2012 Benjamin Franzke
+ * Copyright © 2013 Intel Corporation
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
#include <sys/stat.h>
#include <sys/uio.h>
#include <fcntl.h>
+#include <unistd.h>
#include <xf86drm.h>
union cmsg_data { unsigned char b[4]; int fd; };
+struct weston_launcher {
+ struct weston_compositor *compositor;
+ int fd;
+};
+
int
-weston_launcher_open(struct weston_compositor *compositor,
+weston_launcher_open(struct weston_launcher *launcher,
const char *path, int flags)
{
- int sock = compositor->launcher_sock;
int n, ret = -1;
struct msghdr msg;
struct cmsghdr *cmsg;
ssize_t len;
struct weston_launcher_open *message;
- if (sock == -1)
+ if (launcher == NULL)
return open(path, flags | O_CLOEXEC);
n = sizeof(*message) + strlen(path) + 1;
strcpy(message->path, path);
do {
- len = send(sock, message, n, 0);
+ len = send(launcher->fd, message, n, 0);
} while (len < 0 && errno == EINTR);
free(message);
msg.msg_controllen = sizeof control;
do {
- len = recvmsg(sock, &msg, MSG_CMSG_CLOEXEC);
+ len = recvmsg(launcher->fd, &msg, MSG_CMSG_CLOEXEC);
} while (len < 0 && errno == EINTR);
if (len != sizeof ret ||
}
int
-weston_launcher_drm_set_master(struct weston_compositor *compositor,
+weston_launcher_drm_set_master(struct weston_launcher *launcher,
int drm_fd, char master)
{
struct msghdr msg;
struct weston_launcher_set_master message;
union cmsg_data *data;
- if (compositor->launcher_sock == -1) {
+ if (launcher == NULL) {
if (master)
return drmSetMaster(drm_fd);
else
message.set_master = master;
do {
- len = sendmsg(compositor->launcher_sock, &msg, 0);
+ len = sendmsg(launcher->fd, &msg, 0);
} while (len < 0 && errno == EINTR);
if (len < 0)
return -1;
do {
- len = recv(compositor->launcher_sock, &ret, sizeof ret, 0);
+ len = recv(launcher->fd, &ret, sizeof ret, 0);
} while (len < 0 && errno == EINTR);
if (len < 0)
return -1;
return ret;
}
+struct weston_launcher *
+weston_launcher_connect(struct weston_compositor *compositor)
+{
+ struct weston_launcher *launcher;
+ int fd;
+
+ fd = weston_environment_get_fd("WESTON_LAUNCHER_SOCK");
+ if (fd == -1)
+ return NULL;
+
+ launcher = malloc(sizeof *launcher);
+ if (launcher == NULL)
+ return NULL;
+
+ launcher->compositor = compositor;
+ launcher->fd = fd;
+
+ return launcher;
+}
+
+void
+weston_launcher_destroy(struct weston_launcher *launcher)
+{
+ close(launcher->fd);
+ free(launcher);
+}
#include "compositor.h"
+struct weston_launcher;
+
+struct weston_launcher *
+weston_launcher_connect(struct weston_compositor *compositor);
+
+void
+weston_launcher_destroy(struct weston_launcher *launcher);
+
int
-weston_launcher_open(struct weston_compositor *compositor,
+weston_launcher_open(struct weston_launcher *launcher,
const char *path, int flags);
int
-weston_launcher_drm_set_master(struct weston_compositor *compositor,
+weston_launcher_drm_set_master(struct weston_launcher *launcher,
int drm_fd, char master);
#endif
/* Use non-blocking mode so that we can loop on read on
* evdev_device_data() until all events on the fd are
* read. mtdev_get() also expects this. */
- fd = weston_launcher_open(c, devnode, O_RDWR | O_NONBLOCK);
+ fd = weston_launcher_open(c->launcher, devnode, O_RDWR | O_NONBLOCK);
if (fd < 0) {
weston_log("opening input device '%s' failed.\n", devnode);
return 0;