launcher: Collect launcher state in new struct weston_launcher

We're going to add a bit more launcher state, so start out by creating
a new struct weston_launcher we can track it in.
dev
Kristian Høgsberg 11 years ago
parent bf3c374b1b
commit 05ad1e4e8a
  1. 20
      src/compositor-drm.c
  2. 5
      src/compositor-fbdev.c
  3. 2
      src/compositor.h
  4. 50
      src/launcher-util.c
  5. 12
      src/launcher-util.h
  6. 2
      src/udev-seat.c

@ -1215,7 +1215,7 @@ init_drm(struct drm_compositor *ec, struct udev_device *device)
}
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",
@ -2241,7 +2241,7 @@ drm_restore(struct weston_compositor *ec)
{
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);
}
@ -2265,7 +2265,7 @@ drm_destroy(struct weston_compositor *ec)
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);
@ -2317,7 +2317,8 @@ vt_func(struct weston_compositor *compositor, int event)
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);
}
@ -2356,7 +2357,8 @@ vt_func(struct weston_compositor *compositor, int event)
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;
@ -2571,9 +2573,8 @@ drm_compositor_create(struct wl_display *display,
}
/* 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;
@ -2691,7 +2692,8 @@ err_sprite:
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:

@ -887,9 +887,8 @@ fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[],
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;

@ -590,7 +590,7 @@ struct weston_compositor {
void (*ping_handler)(struct weston_surface *surface, uint32_t serial);
int launcher_sock;
struct weston_launcher *launcher;
uint32_t output_id_pool;

@ -1,5 +1,6 @@
/*
* 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
@ -32,6 +33,7 @@
#include <sys/stat.h>
#include <sys/uio.h>
#include <fcntl.h>
#include <unistd.h>
#include <xf86drm.h>
@ -41,11 +43,15 @@
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;
@ -55,7 +61,7 @@ weston_launcher_open(struct weston_compositor *compositor,
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;
@ -68,7 +74,7 @@ weston_launcher_open(struct weston_compositor *compositor,
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);
@ -81,7 +87,7 @@ weston_launcher_open(struct weston_compositor *compositor,
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 ||
@ -106,7 +112,7 @@ weston_launcher_open(struct weston_compositor *compositor,
}
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;
@ -118,7 +124,7 @@ weston_launcher_drm_set_master(struct weston_compositor *compositor,
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
@ -146,13 +152,13 @@ weston_launcher_drm_set_master(struct weston_compositor *compositor,
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;
@ -160,3 +166,29 @@ weston_launcher_drm_set_master(struct weston_compositor *compositor,
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);
}

@ -27,11 +27,19 @@
#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

@ -75,7 +75,7 @@ device_added(struct udev_device *udev_device, struct udev_input *input)
/* 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;

Loading…
Cancel
Save