2012-01-30 17:04:04 +04:00
|
|
|
/*
|
|
|
|
* Copyright © 2012 Benjamin Franzke
|
2013-09-18 01:41:03 +04:00
|
|
|
* Copyright © 2013 Intel Corporation
|
2012-01-30 17:04:04 +04:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and
|
|
|
|
* its documentation for any purpose is hereby granted without fee, provided
|
|
|
|
* that the above copyright notice appear in all copies and that both that
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
* documentation, and that the name of the copyright holders not be used in
|
|
|
|
* advertising or publicity pertaining to distribution of the software
|
|
|
|
* without specific, written prior permission. The copyright holders make
|
|
|
|
* no representations about the suitability of this software for any
|
|
|
|
* purpose. It is provided "as is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
|
|
|
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2013-05-22 19:03:19 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-01-30 17:04:04 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
2013-09-19 10:00:17 +04:00
|
|
|
#include <signal.h>
|
2012-01-30 17:04:04 +04:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/uio.h>
|
2013-09-19 10:00:17 +04:00
|
|
|
#include <sys/ioctl.h>
|
2012-01-30 17:04:04 +04:00
|
|
|
#include <fcntl.h>
|
2013-09-18 01:41:03 +04:00
|
|
|
#include <unistd.h>
|
2013-09-19 10:00:17 +04:00
|
|
|
#include <linux/vt.h>
|
|
|
|
#include <linux/kd.h>
|
|
|
|
#include <linux/major.h>
|
2012-01-30 17:04:04 +04:00
|
|
|
|
|
|
|
#include "compositor.h"
|
|
|
|
#include "launcher-util.h"
|
2013-10-22 02:28:09 +04:00
|
|
|
#include "logind-util.h"
|
2012-01-30 17:04:04 +04:00
|
|
|
#include "weston-launch.h"
|
|
|
|
|
2013-09-19 10:00:17 +04:00
|
|
|
#define DRM_MAJOR 226
|
|
|
|
|
|
|
|
#ifndef KDSKBMUTE
|
|
|
|
#define KDSKBMUTE 0x4B51
|
|
|
|
#endif
|
|
|
|
|
2013-11-25 02:37:07 +04:00
|
|
|
#ifdef HAVE_LIBDRM
|
2013-09-19 10:00:17 +04:00
|
|
|
|
2013-11-25 02:37:07 +04:00
|
|
|
#include <xf86drm.h>
|
2013-09-18 01:41:03 +04:00
|
|
|
|
2013-11-25 02:37:07 +04:00
|
|
|
static inline int
|
|
|
|
is_drm_master(int drm_fd)
|
2013-10-09 13:30:57 +04:00
|
|
|
{
|
|
|
|
drm_magic_t magic;
|
2013-10-15 00:59:53 +04:00
|
|
|
|
|
|
|
return drmGetMagic(drm_fd, &magic) == 0 &&
|
|
|
|
drmAuthMagic(drm_fd, magic) == 0;
|
2013-10-09 13:30:57 +04:00
|
|
|
}
|
2013-11-25 02:37:07 +04:00
|
|
|
|
2013-10-02 02:37:09 +04:00
|
|
|
#else
|
2013-11-25 02:37:07 +04:00
|
|
|
|
|
|
|
static inline int
|
|
|
|
drmDropMaster(int drm_fd)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
drmSetMaster(int drm_fd)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
is_drm_master(int drm_fd)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-02 02:37:09 +04:00
|
|
|
#endif
|
|
|
|
|
2013-11-25 02:37:07 +04:00
|
|
|
|
|
|
|
union cmsg_data { unsigned char b[4]; int fd; };
|
|
|
|
|
|
|
|
struct weston_launcher {
|
|
|
|
struct weston_compositor *compositor;
|
|
|
|
struct weston_logind *logind;
|
|
|
|
struct wl_event_loop *loop;
|
|
|
|
int fd;
|
|
|
|
struct wl_event_source *source;
|
|
|
|
|
|
|
|
int kb_mode, tty, drm_fd;
|
|
|
|
struct wl_event_source *vt_source;
|
|
|
|
};
|
|
|
|
|
2012-01-30 17:04:04 +04:00
|
|
|
int
|
2013-09-18 01:41:03 +04:00
|
|
|
weston_launcher_open(struct weston_launcher *launcher,
|
2012-01-30 17:04:04 +04:00
|
|
|
const char *path, int flags)
|
|
|
|
{
|
2013-09-19 10:00:17 +04:00
|
|
|
int n, fd, ret = -1;
|
2012-01-30 17:04:04 +04:00
|
|
|
struct msghdr msg;
|
|
|
|
struct cmsghdr *cmsg;
|
|
|
|
struct iovec iov;
|
2012-04-10 09:26:18 +04:00
|
|
|
union cmsg_data *data;
|
|
|
|
char control[CMSG_SPACE(sizeof data->fd)];
|
2012-01-30 17:04:04 +04:00
|
|
|
ssize_t len;
|
|
|
|
struct weston_launcher_open *message;
|
2013-09-19 10:00:17 +04:00
|
|
|
struct stat s;
|
2012-01-30 17:04:04 +04:00
|
|
|
|
2015-05-01 19:46:36 +03:00
|
|
|
/* We really don't want to be leaking fds to child processes so
|
|
|
|
* we force this flag here. If someone comes up with a legitimate
|
|
|
|
* reason to not CLOEXEC they'll need to unset the flag manually.
|
|
|
|
*/
|
|
|
|
flags |= O_CLOEXEC;
|
|
|
|
|
2013-10-22 02:28:09 +04:00
|
|
|
if (launcher->logind)
|
|
|
|
return weston_logind_open(launcher->logind, path, flags);
|
|
|
|
|
2013-09-19 10:00:17 +04:00
|
|
|
if (launcher->fd == -1) {
|
2015-05-01 19:46:36 +03:00
|
|
|
fd = open(path, flags);
|
2013-09-19 10:00:17 +04:00
|
|
|
if (fd == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (fstat(fd, &s) == -1) {
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-02 02:37:09 +04:00
|
|
|
if (major(s.st_rdev) == DRM_MAJOR) {
|
2013-09-19 10:00:17 +04:00
|
|
|
launcher->drm_fd = fd;
|
2013-11-25 02:37:07 +04:00
|
|
|
if (!is_drm_master(fd)) {
|
2013-10-02 21:49:05 +04:00
|
|
|
weston_log("drm fd not master\n");
|
2013-10-02 02:37:09 +04:00
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2013-09-19 10:00:17 +04:00
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
2012-01-30 17:04:04 +04:00
|
|
|
|
|
|
|
n = sizeof(*message) + strlen(path) + 1;
|
|
|
|
message = malloc(n);
|
|
|
|
if (!message)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
message->header.opcode = WESTON_LAUNCHER_OPEN;
|
|
|
|
message->flags = flags;
|
|
|
|
strcpy(message->path, path);
|
|
|
|
|
|
|
|
do {
|
2013-09-18 01:41:03 +04:00
|
|
|
len = send(launcher->fd, message, n, 0);
|
2012-01-30 17:04:04 +04:00
|
|
|
} while (len < 0 && errno == EINTR);
|
2012-04-10 09:31:09 +04:00
|
|
|
free(message);
|
2012-01-30 17:04:04 +04:00
|
|
|
|
|
|
|
memset(&msg, 0, sizeof msg);
|
|
|
|
iov.iov_base = &ret;
|
|
|
|
iov.iov_len = sizeof ret;
|
|
|
|
msg.msg_iov = &iov;
|
|
|
|
msg.msg_iovlen = 1;
|
|
|
|
msg.msg_control = control;
|
|
|
|
msg.msg_controllen = sizeof control;
|
|
|
|
|
|
|
|
do {
|
2013-09-18 01:41:03 +04:00
|
|
|
len = recvmsg(launcher->fd, &msg, MSG_CMSG_CLOEXEC);
|
2012-01-30 17:04:04 +04:00
|
|
|
} while (len < 0 && errno == EINTR);
|
|
|
|
|
|
|
|
if (len != sizeof ret ||
|
|
|
|
ret < 0)
|
2012-04-10 09:31:09 +04:00
|
|
|
return -1;
|
2012-01-30 17:04:04 +04:00
|
|
|
|
|
|
|
cmsg = CMSG_FIRSTHDR(&msg);
|
|
|
|
if (!cmsg ||
|
|
|
|
cmsg->cmsg_level != SOL_SOCKET ||
|
|
|
|
cmsg->cmsg_type != SCM_RIGHTS) {
|
|
|
|
fprintf(stderr, "invalid control message\n");
|
2012-04-10 09:31:09 +04:00
|
|
|
return -1;
|
2012-01-30 17:04:04 +04:00
|
|
|
}
|
|
|
|
|
2012-04-10 09:26:18 +04:00
|
|
|
data = (union cmsg_data *) CMSG_DATA(cmsg);
|
|
|
|
if (data->fd == -1) {
|
2013-02-13 03:11:12 +04:00
|
|
|
fprintf(stderr, "missing drm fd in socket request\n");
|
2012-01-30 17:04:04 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-04-10 09:31:09 +04:00
|
|
|
return data->fd;
|
2012-01-30 17:04:04 +04:00
|
|
|
}
|
|
|
|
|
2013-10-22 02:28:08 +04:00
|
|
|
void
|
|
|
|
weston_launcher_close(struct weston_launcher *launcher, int fd)
|
|
|
|
{
|
2013-10-22 02:28:09 +04:00
|
|
|
if (launcher->logind)
|
2015-04-30 22:37:03 +03:00
|
|
|
weston_logind_close(launcher->logind, fd);
|
2013-10-22 02:28:09 +04:00
|
|
|
|
2013-10-22 02:28:08 +04:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
2013-09-19 10:00:17 +04:00
|
|
|
void
|
|
|
|
weston_launcher_restore(struct weston_launcher *launcher)
|
|
|
|
{
|
|
|
|
struct vt_mode mode = { 0 };
|
|
|
|
|
2013-10-22 02:28:09 +04:00
|
|
|
if (launcher->logind)
|
|
|
|
return weston_logind_restore(launcher->logind);
|
|
|
|
|
2013-09-19 10:00:17 +04:00
|
|
|
if (ioctl(launcher->tty, KDSKBMUTE, 0) &&
|
|
|
|
ioctl(launcher->tty, KDSKBMODE, launcher->kb_mode))
|
|
|
|
weston_log("failed to restore kb mode: %m\n");
|
|
|
|
|
|
|
|
if (ioctl(launcher->tty, KDSETMODE, KD_TEXT))
|
|
|
|
weston_log("failed to set KD_TEXT mode on tty: %m\n");
|
|
|
|
|
2013-10-31 03:27:16 +04:00
|
|
|
/* We have to drop master before we switch the VT back in
|
|
|
|
* VT_AUTO, so we don't risk switching to a VT with another
|
|
|
|
* display server, that will then fail to set drm master. */
|
2013-11-25 02:37:07 +04:00
|
|
|
drmDropMaster(launcher->drm_fd);
|
2013-10-31 03:27:16 +04:00
|
|
|
|
2013-09-19 10:00:17 +04:00
|
|
|
mode.mode = VT_AUTO;
|
|
|
|
if (ioctl(launcher->tty, VT_SETMODE, &mode) < 0)
|
|
|
|
weston_log("could not reset vt handling\n");
|
|
|
|
}
|
|
|
|
|
2013-09-18 09:15:37 +04:00
|
|
|
static int
|
|
|
|
weston_launcher_data(int fd, uint32_t mask, void *data)
|
2012-01-30 17:04:04 +04:00
|
|
|
{
|
2013-09-18 09:15:37 +04:00
|
|
|
struct weston_launcher *launcher = data;
|
|
|
|
int len, ret;
|
2012-01-30 17:04:04 +04:00
|
|
|
|
2013-09-18 09:15:37 +04:00
|
|
|
if (mask & (WL_EVENT_HANGUP | WL_EVENT_ERROR)) {
|
|
|
|
weston_log("launcher socket closed, exiting\n");
|
2013-09-19 10:00:17 +04:00
|
|
|
/* Normally the weston-launch will reset the tty, but
|
|
|
|
* in this case it died or something, so do it here so
|
|
|
|
* we don't end up with a stuck vt. */
|
|
|
|
weston_launcher_restore(launcher);
|
2013-09-18 09:15:37 +04:00
|
|
|
exit(-1);
|
2012-01-30 17:04:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2013-09-18 01:41:03 +04:00
|
|
|
len = recv(launcher->fd, &ret, sizeof ret, 0);
|
2012-01-30 17:04:04 +04:00
|
|
|
} while (len < 0 && errno == EINTR);
|
|
|
|
|
2013-09-18 09:15:37 +04:00
|
|
|
switch (ret) {
|
|
|
|
case WESTON_LAUNCHER_ACTIVATE:
|
|
|
|
launcher->compositor->session_active = 1;
|
|
|
|
wl_signal_emit(&launcher->compositor->session_signal,
|
|
|
|
launcher->compositor);
|
|
|
|
break;
|
|
|
|
case WESTON_LAUNCHER_DEACTIVATE:
|
|
|
|
launcher->compositor->session_active = 0;
|
|
|
|
wl_signal_emit(&launcher->compositor->session_signal,
|
|
|
|
launcher->compositor);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
weston_log("unexpected event from weston-launch\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2012-01-30 17:04:04 +04:00
|
|
|
}
|
|
|
|
|
2013-09-19 10:00:17 +04:00
|
|
|
static int
|
|
|
|
vt_handler(int signal_number, void *data)
|
|
|
|
{
|
|
|
|
struct weston_launcher *launcher = data;
|
|
|
|
struct weston_compositor *compositor = launcher->compositor;
|
|
|
|
|
|
|
|
if (compositor->session_active) {
|
|
|
|
compositor->session_active = 0;
|
|
|
|
wl_signal_emit(&compositor->session_signal, compositor);
|
2013-11-25 02:37:07 +04:00
|
|
|
drmDropMaster(launcher->drm_fd);
|
2013-09-19 10:00:17 +04:00
|
|
|
ioctl(launcher->tty, VT_RELDISP, 1);
|
|
|
|
} else {
|
|
|
|
ioctl(launcher->tty, VT_RELDISP, VT_ACKACQ);
|
2013-11-25 02:37:07 +04:00
|
|
|
drmSetMaster(launcher->drm_fd);
|
2013-09-19 10:00:17 +04:00
|
|
|
compositor->session_active = 1;
|
|
|
|
wl_signal_emit(&compositor->session_signal, compositor);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-10-02 21:53:33 +04:00
|
|
|
setup_tty(struct weston_launcher *launcher, int tty)
|
2013-09-19 10:00:17 +04:00
|
|
|
{
|
|
|
|
struct wl_event_loop *loop;
|
|
|
|
struct vt_mode mode = { 0 };
|
|
|
|
struct stat buf;
|
2013-10-02 21:53:33 +04:00
|
|
|
char tty_device[32] ="<stdin>";
|
|
|
|
int ret, kd_mode;
|
2013-09-19 10:00:17 +04:00
|
|
|
|
2013-10-02 21:53:33 +04:00
|
|
|
if (tty == 0) {
|
2013-10-09 22:03:39 +04:00
|
|
|
launcher->tty = dup(tty);
|
|
|
|
if (launcher->tty == -1) {
|
|
|
|
weston_log("couldn't dup stdin: %m\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2013-10-02 21:53:33 +04:00
|
|
|
} else {
|
|
|
|
snprintf(tty_device, sizeof tty_device, "/dev/tty%d", tty);
|
|
|
|
launcher->tty = open(tty_device, O_RDWR | O_CLOEXEC);
|
|
|
|
if (launcher->tty == -1) {
|
|
|
|
weston_log("couldn't open tty %s: %m\n", tty_device);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fstat(launcher->tty, &buf) == -1 ||
|
2013-09-19 10:00:17 +04:00
|
|
|
major(buf.st_rdev) != TTY_MAJOR || minor(buf.st_rdev) == 0) {
|
2013-10-02 21:53:33 +04:00
|
|
|
weston_log("%s not a vt\n", tty_device);
|
2013-10-01 23:54:55 +04:00
|
|
|
weston_log("if running weston from ssh, "
|
|
|
|
"use --tty to specify a tty\n");
|
2013-10-09 22:19:11 +04:00
|
|
|
goto err_close;
|
2013-09-19 10:00:17 +04:00
|
|
|
}
|
|
|
|
|
2013-10-02 21:53:33 +04:00
|
|
|
ret = ioctl(launcher->tty, KDGETMODE, &kd_mode);
|
|
|
|
if (ret) {
|
|
|
|
weston_log("failed to get VT mode: %m\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (kd_mode != KD_TEXT) {
|
|
|
|
weston_log("%s is already in graphics mode, "
|
|
|
|
"is another display server running?\n", tty_device);
|
2013-10-09 22:19:11 +04:00
|
|
|
goto err_close;
|
2013-10-02 21:53:33 +04:00
|
|
|
}
|
|
|
|
|
2013-10-10 00:10:42 +04:00
|
|
|
ioctl(launcher->tty, VT_ACTIVATE, minor(buf.st_rdev));
|
|
|
|
ioctl(launcher->tty, VT_WAITACTIVE, minor(buf.st_rdev));
|
2013-10-02 21:53:33 +04:00
|
|
|
|
2013-09-19 10:00:17 +04:00
|
|
|
if (ioctl(launcher->tty, KDGKBMODE, &launcher->kb_mode)) {
|
|
|
|
weston_log("failed to read keyboard mode: %m\n");
|
2013-10-09 22:19:11 +04:00
|
|
|
goto err_close;
|
2013-09-19 10:00:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(launcher->tty, KDSKBMUTE, 1) &&
|
|
|
|
ioctl(launcher->tty, KDSKBMODE, K_OFF)) {
|
|
|
|
weston_log("failed to set K_OFF keyboard mode: %m\n");
|
2013-10-09 22:19:11 +04:00
|
|
|
goto err_close;
|
2013-09-19 10:00:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = ioctl(launcher->tty, KDSETMODE, KD_GRAPHICS);
|
|
|
|
if (ret) {
|
|
|
|
weston_log("failed to set KD_GRAPHICS mode on tty: %m\n");
|
2013-10-09 22:19:11 +04:00
|
|
|
goto err_close;
|
2013-09-19 10:00:17 +04:00
|
|
|
}
|
|
|
|
|
2014-12-30 16:33:21 +03:00
|
|
|
/*
|
|
|
|
* SIGRTMIN is used as global VT-acquire+release signal. Note that
|
|
|
|
* SIGRT* must be tested on runtime, as their exact values are not
|
|
|
|
* known at compile-time. POSIX requires 32 of them to be available.
|
|
|
|
*/
|
|
|
|
if (SIGRTMIN > SIGRTMAX) {
|
|
|
|
weston_log("not enough RT signals available: %u-%u\n",
|
|
|
|
SIGRTMIN, SIGRTMAX);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err_close;
|
|
|
|
}
|
|
|
|
|
2013-09-19 10:00:17 +04:00
|
|
|
mode.mode = VT_PROCESS;
|
2014-12-30 16:33:21 +03:00
|
|
|
mode.relsig = SIGRTMIN;
|
|
|
|
mode.acqsig = SIGRTMIN;
|
2013-09-19 10:00:17 +04:00
|
|
|
if (ioctl(launcher->tty, VT_SETMODE, &mode) < 0) {
|
|
|
|
weston_log("failed to take control of vt handling\n");
|
2013-10-09 22:19:11 +04:00
|
|
|
goto err_close;
|
2013-09-19 10:00:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
loop = wl_display_get_event_loop(launcher->compositor->wl_display);
|
|
|
|
launcher->vt_source =
|
2014-12-30 16:33:21 +03:00
|
|
|
wl_event_loop_add_signal(loop, SIGRTMIN, vt_handler, launcher);
|
2013-09-19 10:00:17 +04:00
|
|
|
if (!launcher->vt_source)
|
2013-10-09 22:19:11 +04:00
|
|
|
goto err_close;
|
2013-09-19 10:00:17 +04:00
|
|
|
|
|
|
|
return 0;
|
2013-10-09 22:19:11 +04:00
|
|
|
|
|
|
|
err_close:
|
|
|
|
close(launcher->tty);
|
|
|
|
return -1;
|
2013-09-19 10:00:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
weston_launcher_activate_vt(struct weston_launcher *launcher, int vt)
|
|
|
|
{
|
2013-10-22 02:28:09 +04:00
|
|
|
if (launcher->logind)
|
|
|
|
return weston_logind_activate_vt(launcher->logind, vt);
|
|
|
|
|
2013-09-19 10:00:17 +04:00
|
|
|
return ioctl(launcher->tty, VT_ACTIVATE, vt);
|
|
|
|
}
|
|
|
|
|
2013-09-18 01:41:03 +04:00
|
|
|
struct weston_launcher *
|
2013-10-22 02:28:09 +04:00
|
|
|
weston_launcher_connect(struct weston_compositor *compositor, int tty,
|
2014-12-30 16:33:22 +03:00
|
|
|
const char *seat_id, bool sync_drm)
|
2013-09-18 01:41:03 +04:00
|
|
|
{
|
|
|
|
struct weston_launcher *launcher;
|
2013-09-18 09:15:37 +04:00
|
|
|
struct wl_event_loop *loop;
|
2013-10-22 02:28:09 +04:00
|
|
|
int r;
|
2013-09-18 01:41:03 +04:00
|
|
|
|
|
|
|
launcher = malloc(sizeof *launcher);
|
|
|
|
if (launcher == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2013-10-22 02:28:09 +04:00
|
|
|
launcher->logind = NULL;
|
2013-09-18 01:41:03 +04:00
|
|
|
launcher->compositor = compositor;
|
2013-09-19 10:00:17 +04:00
|
|
|
launcher->drm_fd = -1;
|
|
|
|
launcher->fd = weston_environment_get_fd("WESTON_LAUNCHER_SOCK");
|
|
|
|
if (launcher->fd != -1) {
|
|
|
|
launcher->tty = weston_environment_get_fd("WESTON_TTY_FD");
|
2014-04-30 21:40:39 +04:00
|
|
|
/* We don't get a chance to read out the original kb
|
|
|
|
* mode for the tty, so just hard code K_UNICODE here
|
|
|
|
* in case we have to clean if weston-launch dies. */
|
|
|
|
launcher->kb_mode = K_UNICODE;
|
|
|
|
|
2013-09-19 10:00:17 +04:00
|
|
|
loop = wl_display_get_event_loop(compositor->wl_display);
|
|
|
|
launcher->source = wl_event_loop_add_fd(loop, launcher->fd,
|
|
|
|
WL_EVENT_READABLE,
|
|
|
|
weston_launcher_data,
|
|
|
|
launcher);
|
|
|
|
if (launcher->source == NULL) {
|
|
|
|
free(launcher);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
2013-10-22 02:28:09 +04:00
|
|
|
r = weston_logind_connect(&launcher->logind, compositor,
|
2014-12-30 16:33:22 +03:00
|
|
|
seat_id, tty, sync_drm);
|
2013-10-22 02:28:09 +04:00
|
|
|
if (r < 0) {
|
|
|
|
launcher->logind = NULL;
|
|
|
|
if (geteuid() == 0) {
|
|
|
|
if (setup_tty(launcher, tty) == -1) {
|
|
|
|
free(launcher);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
free(launcher);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2013-09-18 09:15:37 +04:00
|
|
|
}
|
|
|
|
|
2013-09-18 01:41:03 +04:00
|
|
|
return launcher;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
weston_launcher_destroy(struct weston_launcher *launcher)
|
|
|
|
{
|
2013-10-23 00:19:23 +04:00
|
|
|
if (launcher->logind) {
|
2013-10-22 02:28:09 +04:00
|
|
|
weston_logind_destroy(launcher->logind);
|
2013-10-23 00:19:23 +04:00
|
|
|
} else if (launcher->fd != -1) {
|
2013-09-19 10:00:17 +04:00
|
|
|
close(launcher->fd);
|
|
|
|
wl_event_source_remove(launcher->source);
|
|
|
|
} else {
|
|
|
|
weston_launcher_restore(launcher);
|
|
|
|
wl_event_source_remove(launcher->vt_source);
|
|
|
|
}
|
|
|
|
|
2013-10-22 02:28:09 +04:00
|
|
|
if (launcher->tty >= 0)
|
|
|
|
close(launcher->tty);
|
|
|
|
|
2013-09-18 01:41:03 +04:00
|
|
|
free(launcher);
|
|
|
|
}
|