blob: e89710bcc6289f67331ce4e441e3cdedce904d00 [file] [log] [blame]
Benjamin Franzkebfeda132012-01-30 14:04:04 +01001/*
2 * Copyright © 2012 Benjamin Franzke
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -07003 * Copyright © 2013 Intel Corporation
Benjamin Franzkebfeda132012-01-30 14:04:04 +01004 *
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of the copyright holders not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission. The copyright holders make
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
14 *
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 */
23
Daniel Stonec228e232013-05-22 18:03:19 +030024#include "config.h"
25
Benjamin Franzkebfeda132012-01-30 14:04:04 +010026#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29
30#include <errno.h>
Kristian Høgsberg3f495872013-09-18 23:00:17 -070031#include <signal.h>
Benjamin Franzkebfeda132012-01-30 14:04:04 +010032#include <sys/socket.h>
33#include <sys/types.h>
34#include <sys/stat.h>
35#include <sys/uio.h>
Kristian Høgsberg3f495872013-09-18 23:00:17 -070036#include <sys/ioctl.h>
Benjamin Franzkebfeda132012-01-30 14:04:04 +010037#include <fcntl.h>
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -070038#include <unistd.h>
Kristian Høgsberg3f495872013-09-18 23:00:17 -070039#include <linux/vt.h>
40#include <linux/kd.h>
41#include <linux/major.h>
Benjamin Franzkebfeda132012-01-30 14:04:04 +010042
Benjamin Franzkebfeda132012-01-30 14:04:04 +010043#include "compositor.h"
44#include "launcher-util.h"
David Herrmanncc5b2ed2013-10-22 00:28:09 +020045#include "logind-util.h"
Benjamin Franzkebfeda132012-01-30 14:04:04 +010046#include "weston-launch.h"
47
Kristian Høgsberg3f495872013-09-18 23:00:17 -070048#define DRM_MAJOR 226
49
50#ifndef KDSKBMUTE
51#define KDSKBMUTE 0x4B51
52#endif
53
Kristian Høgsbergd2c9d8a2013-11-24 14:37:07 -080054#ifdef HAVE_LIBDRM
Kristian Høgsberg9e140912012-04-10 01:26:18 -040055
Kristian Høgsbergd2c9d8a2013-11-24 14:37:07 -080056#include <xf86drm.h>
Kristian Høgsberg3f495872013-09-18 23:00:17 -070057
Kristian Høgsbergd2c9d8a2013-11-24 14:37:07 -080058static inline int
59is_drm_master(int drm_fd)
Tomeu Vizoso0b12db52013-10-09 11:30:57 +020060{
61 drm_magic_t magic;
Kristian Høgsberg891a16d2013-10-14 13:59:53 -070062
63 return drmGetMagic(drm_fd, &magic) == 0 &&
64 drmAuthMagic(drm_fd, magic) == 0;
Tomeu Vizoso0b12db52013-10-09 11:30:57 +020065}
Kristian Høgsbergd2c9d8a2013-11-24 14:37:07 -080066
Kristian Høgsberg57a10e42013-10-01 15:37:09 -070067#else
Kristian Høgsbergd2c9d8a2013-11-24 14:37:07 -080068
69static inline int
70drmDropMaster(int drm_fd)
71{
72 return 0;
73}
74
75static inline int
76drmSetMaster(int drm_fd)
77{
78 return 0;
79}
80
81static inline int
82is_drm_master(int drm_fd)
83{
84 return 0;
85}
86
Kristian Høgsberg57a10e42013-10-01 15:37:09 -070087#endif
88
Kristian Høgsbergd2c9d8a2013-11-24 14:37:07 -080089
90union cmsg_data { unsigned char b[4]; int fd; };
91
92struct weston_launcher {
93 struct weston_compositor *compositor;
94 struct weston_logind *logind;
95 struct wl_event_loop *loop;
96 int fd;
97 struct wl_event_source *source;
98
99 int kb_mode, tty, drm_fd;
100 struct wl_event_source *vt_source;
101};
102
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100103int
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -0700104weston_launcher_open(struct weston_launcher *launcher,
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100105 const char *path, int flags)
106{
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700107 int n, fd, ret = -1;
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100108 struct msghdr msg;
109 struct cmsghdr *cmsg;
110 struct iovec iov;
Kristian Høgsberg9e140912012-04-10 01:26:18 -0400111 union cmsg_data *data;
112 char control[CMSG_SPACE(sizeof data->fd)];
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100113 ssize_t len;
114 struct weston_launcher_open *message;
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700115 struct stat s;
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100116
David Herrmanncc5b2ed2013-10-22 00:28:09 +0200117 if (launcher->logind)
118 return weston_logind_open(launcher->logind, path, flags);
119
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700120 if (launcher->fd == -1) {
121 fd = open(path, flags | O_CLOEXEC);
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700122 if (fd == -1)
123 return -1;
124
125 if (fstat(fd, &s) == -1) {
126 close(fd);
127 return -1;
128 }
129
Kristian Høgsberg57a10e42013-10-01 15:37:09 -0700130 if (major(s.st_rdev) == DRM_MAJOR) {
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700131 launcher->drm_fd = fd;
Kristian Høgsbergd2c9d8a2013-11-24 14:37:07 -0800132 if (!is_drm_master(fd)) {
Kristian Høgsberg1468e602013-10-02 10:49:05 -0700133 weston_log("drm fd not master\n");
Kristian Høgsberg57a10e42013-10-01 15:37:09 -0700134 close(fd);
135 return -1;
136 }
137 }
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700138
139 return fd;
140 }
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100141
142 n = sizeof(*message) + strlen(path) + 1;
143 message = malloc(n);
144 if (!message)
145 return -1;
146
147 message->header.opcode = WESTON_LAUNCHER_OPEN;
148 message->flags = flags;
149 strcpy(message->path, path);
150
151 do {
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -0700152 len = send(launcher->fd, message, n, 0);
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100153 } while (len < 0 && errno == EINTR);
Kristian Høgsbergba25bd72012-04-10 01:31:09 -0400154 free(message);
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100155
156 memset(&msg, 0, sizeof msg);
157 iov.iov_base = &ret;
158 iov.iov_len = sizeof ret;
159 msg.msg_iov = &iov;
160 msg.msg_iovlen = 1;
161 msg.msg_control = control;
162 msg.msg_controllen = sizeof control;
163
164 do {
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -0700165 len = recvmsg(launcher->fd, &msg, MSG_CMSG_CLOEXEC);
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100166 } while (len < 0 && errno == EINTR);
167
168 if (len != sizeof ret ||
169 ret < 0)
Kristian Høgsbergba25bd72012-04-10 01:31:09 -0400170 return -1;
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100171
172 cmsg = CMSG_FIRSTHDR(&msg);
173 if (!cmsg ||
174 cmsg->cmsg_level != SOL_SOCKET ||
175 cmsg->cmsg_type != SCM_RIGHTS) {
176 fprintf(stderr, "invalid control message\n");
Kristian Høgsbergba25bd72012-04-10 01:31:09 -0400177 return -1;
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100178 }
179
Kristian Høgsberg9e140912012-04-10 01:26:18 -0400180 data = (union cmsg_data *) CMSG_DATA(cmsg);
181 if (data->fd == -1) {
Martin Andersson566b4642013-02-13 00:11:12 +0100182 fprintf(stderr, "missing drm fd in socket request\n");
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100183 return -1;
184 }
185
Kristian Høgsbergba25bd72012-04-10 01:31:09 -0400186 return data->fd;
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100187}
188
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700189void
David Herrmanne461f852013-10-22 00:28:08 +0200190weston_launcher_close(struct weston_launcher *launcher, int fd)
191{
David Herrmanncc5b2ed2013-10-22 00:28:09 +0200192 if (launcher->logind)
193 return weston_logind_close(launcher->logind, fd);
194
David Herrmanne461f852013-10-22 00:28:08 +0200195 close(fd);
196}
197
198void
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700199weston_launcher_restore(struct weston_launcher *launcher)
200{
201 struct vt_mode mode = { 0 };
202
David Herrmanncc5b2ed2013-10-22 00:28:09 +0200203 if (launcher->logind)
204 return weston_logind_restore(launcher->logind);
205
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700206 if (ioctl(launcher->tty, KDSKBMUTE, 0) &&
207 ioctl(launcher->tty, KDSKBMODE, launcher->kb_mode))
208 weston_log("failed to restore kb mode: %m\n");
209
210 if (ioctl(launcher->tty, KDSETMODE, KD_TEXT))
211 weston_log("failed to set KD_TEXT mode on tty: %m\n");
212
Kristian Høgsberga28ba552013-10-30 16:27:16 -0700213 /* We have to drop master before we switch the VT back in
214 * VT_AUTO, so we don't risk switching to a VT with another
215 * display server, that will then fail to set drm master. */
Kristian Høgsbergd2c9d8a2013-11-24 14:37:07 -0800216 drmDropMaster(launcher->drm_fd);
Kristian Høgsberga28ba552013-10-30 16:27:16 -0700217
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700218 mode.mode = VT_AUTO;
219 if (ioctl(launcher->tty, VT_SETMODE, &mode) < 0)
220 weston_log("could not reset vt handling\n");
221}
222
Kristian Høgsberg1eb482d2013-09-17 22:15:37 -0700223static int
224weston_launcher_data(int fd, uint32_t mask, void *data)
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100225{
Kristian Høgsberg1eb482d2013-09-17 22:15:37 -0700226 struct weston_launcher *launcher = data;
227 int len, ret;
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100228
Kristian Høgsberg1eb482d2013-09-17 22:15:37 -0700229 if (mask & (WL_EVENT_HANGUP | WL_EVENT_ERROR)) {
230 weston_log("launcher socket closed, exiting\n");
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700231 /* Normally the weston-launch will reset the tty, but
232 * in this case it died or something, so do it here so
233 * we don't end up with a stuck vt. */
234 weston_launcher_restore(launcher);
Kristian Høgsberg1eb482d2013-09-17 22:15:37 -0700235 exit(-1);
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100236 }
237
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100238 do {
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -0700239 len = recv(launcher->fd, &ret, sizeof ret, 0);
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100240 } while (len < 0 && errno == EINTR);
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100241
Kristian Høgsberg1eb482d2013-09-17 22:15:37 -0700242 switch (ret) {
243 case WESTON_LAUNCHER_ACTIVATE:
244 launcher->compositor->session_active = 1;
245 wl_signal_emit(&launcher->compositor->session_signal,
246 launcher->compositor);
247 break;
248 case WESTON_LAUNCHER_DEACTIVATE:
249 launcher->compositor->session_active = 0;
250 wl_signal_emit(&launcher->compositor->session_signal,
251 launcher->compositor);
252 break;
253 default:
254 weston_log("unexpected event from weston-launch\n");
255 break;
256 }
257
258 return 1;
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100259}
260
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700261static int
262vt_handler(int signal_number, void *data)
263{
264 struct weston_launcher *launcher = data;
265 struct weston_compositor *compositor = launcher->compositor;
266
267 if (compositor->session_active) {
268 compositor->session_active = 0;
269 wl_signal_emit(&compositor->session_signal, compositor);
Kristian Høgsbergd2c9d8a2013-11-24 14:37:07 -0800270 drmDropMaster(launcher->drm_fd);
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700271 ioctl(launcher->tty, VT_RELDISP, 1);
272 } else {
273 ioctl(launcher->tty, VT_RELDISP, VT_ACKACQ);
Kristian Høgsbergd2c9d8a2013-11-24 14:37:07 -0800274 drmSetMaster(launcher->drm_fd);
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700275 compositor->session_active = 1;
276 wl_signal_emit(&compositor->session_signal, compositor);
277 }
278
279 return 1;
280}
281
282static int
Kristian Høgsberg6ff3ff52013-10-02 10:53:33 -0700283setup_tty(struct weston_launcher *launcher, int tty)
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700284{
285 struct wl_event_loop *loop;
286 struct vt_mode mode = { 0 };
287 struct stat buf;
Kristian Høgsberg6ff3ff52013-10-02 10:53:33 -0700288 char tty_device[32] ="<stdin>";
289 int ret, kd_mode;
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700290
Kristian Høgsberg6ff3ff52013-10-02 10:53:33 -0700291 if (tty == 0) {
Kristian Høgsberg325390e2013-10-09 11:03:39 -0700292 launcher->tty = dup(tty);
293 if (launcher->tty == -1) {
294 weston_log("couldn't dup stdin: %m\n");
295 return -1;
296 }
Kristian Høgsberg6ff3ff52013-10-02 10:53:33 -0700297 } else {
298 snprintf(tty_device, sizeof tty_device, "/dev/tty%d", tty);
299 launcher->tty = open(tty_device, O_RDWR | O_CLOEXEC);
300 if (launcher->tty == -1) {
301 weston_log("couldn't open tty %s: %m\n", tty_device);
302 return -1;
303 }
304 }
305
306 if (fstat(launcher->tty, &buf) == -1 ||
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700307 major(buf.st_rdev) != TTY_MAJOR || minor(buf.st_rdev) == 0) {
Kristian Høgsberg6ff3ff52013-10-02 10:53:33 -0700308 weston_log("%s not a vt\n", tty_device);
Kristian Høgsberg19ec77a2013-10-01 12:54:55 -0700309 weston_log("if running weston from ssh, "
310 "use --tty to specify a tty\n");
Kristian Høgsberg4a74d5a2013-10-09 11:19:11 -0700311 goto err_close;
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700312 }
313
Kristian Høgsberg6ff3ff52013-10-02 10:53:33 -0700314 ret = ioctl(launcher->tty, KDGETMODE, &kd_mode);
315 if (ret) {
316 weston_log("failed to get VT mode: %m\n");
317 return -1;
318 }
319 if (kd_mode != KD_TEXT) {
320 weston_log("%s is already in graphics mode, "
321 "is another display server running?\n", tty_device);
Kristian Høgsberg4a74d5a2013-10-09 11:19:11 -0700322 goto err_close;
Kristian Høgsberg6ff3ff52013-10-02 10:53:33 -0700323 }
324
Kristian Høgsberg74b0d722013-10-09 13:10:42 -0700325 ioctl(launcher->tty, VT_ACTIVATE, minor(buf.st_rdev));
326 ioctl(launcher->tty, VT_WAITACTIVE, minor(buf.st_rdev));
Kristian Høgsberg6ff3ff52013-10-02 10:53:33 -0700327
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700328 if (ioctl(launcher->tty, KDGKBMODE, &launcher->kb_mode)) {
329 weston_log("failed to read keyboard mode: %m\n");
Kristian Høgsberg4a74d5a2013-10-09 11:19:11 -0700330 goto err_close;
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700331 }
332
333 if (ioctl(launcher->tty, KDSKBMUTE, 1) &&
334 ioctl(launcher->tty, KDSKBMODE, K_OFF)) {
335 weston_log("failed to set K_OFF keyboard mode: %m\n");
Kristian Høgsberg4a74d5a2013-10-09 11:19:11 -0700336 goto err_close;
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700337 }
338
339 ret = ioctl(launcher->tty, KDSETMODE, KD_GRAPHICS);
340 if (ret) {
341 weston_log("failed to set KD_GRAPHICS mode on tty: %m\n");
Kristian Høgsberg4a74d5a2013-10-09 11:19:11 -0700342 goto err_close;
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700343 }
344
David Herrmann541b6042014-12-30 14:33:21 +0100345 /*
346 * SIGRTMIN is used as global VT-acquire+release signal. Note that
347 * SIGRT* must be tested on runtime, as their exact values are not
348 * known at compile-time. POSIX requires 32 of them to be available.
349 */
350 if (SIGRTMIN > SIGRTMAX) {
351 weston_log("not enough RT signals available: %u-%u\n",
352 SIGRTMIN, SIGRTMAX);
353 ret = -EINVAL;
354 goto err_close;
355 }
356
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700357 mode.mode = VT_PROCESS;
David Herrmann541b6042014-12-30 14:33:21 +0100358 mode.relsig = SIGRTMIN;
359 mode.acqsig = SIGRTMIN;
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700360 if (ioctl(launcher->tty, VT_SETMODE, &mode) < 0) {
361 weston_log("failed to take control of vt handling\n");
Kristian Høgsberg4a74d5a2013-10-09 11:19:11 -0700362 goto err_close;
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700363 }
364
365 loop = wl_display_get_event_loop(launcher->compositor->wl_display);
366 launcher->vt_source =
David Herrmann541b6042014-12-30 14:33:21 +0100367 wl_event_loop_add_signal(loop, SIGRTMIN, vt_handler, launcher);
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700368 if (!launcher->vt_source)
Kristian Høgsberg4a74d5a2013-10-09 11:19:11 -0700369 goto err_close;
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700370
371 return 0;
Kristian Høgsberg4a74d5a2013-10-09 11:19:11 -0700372
373 err_close:
374 close(launcher->tty);
375 return -1;
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700376}
377
378int
379weston_launcher_activate_vt(struct weston_launcher *launcher, int vt)
380{
David Herrmanncc5b2ed2013-10-22 00:28:09 +0200381 if (launcher->logind)
382 return weston_logind_activate_vt(launcher->logind, vt);
383
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700384 return ioctl(launcher->tty, VT_ACTIVATE, vt);
385}
386
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -0700387struct weston_launcher *
David Herrmanncc5b2ed2013-10-22 00:28:09 +0200388weston_launcher_connect(struct weston_compositor *compositor, int tty,
David Herrmann2ecb84a2014-12-30 14:33:22 +0100389 const char *seat_id, bool sync_drm)
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -0700390{
391 struct weston_launcher *launcher;
Kristian Høgsberg1eb482d2013-09-17 22:15:37 -0700392 struct wl_event_loop *loop;
David Herrmanncc5b2ed2013-10-22 00:28:09 +0200393 int r;
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -0700394
395 launcher = malloc(sizeof *launcher);
396 if (launcher == NULL)
397 return NULL;
398
David Herrmanncc5b2ed2013-10-22 00:28:09 +0200399 launcher->logind = NULL;
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -0700400 launcher->compositor = compositor;
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700401 launcher->drm_fd = -1;
402 launcher->fd = weston_environment_get_fd("WESTON_LAUNCHER_SOCK");
403 if (launcher->fd != -1) {
404 launcher->tty = weston_environment_get_fd("WESTON_TTY_FD");
Kristian Høgsberg9a14b8f2014-04-30 10:40:39 -0700405 /* We don't get a chance to read out the original kb
406 * mode for the tty, so just hard code K_UNICODE here
407 * in case we have to clean if weston-launch dies. */
408 launcher->kb_mode = K_UNICODE;
409
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700410 loop = wl_display_get_event_loop(compositor->wl_display);
411 launcher->source = wl_event_loop_add_fd(loop, launcher->fd,
412 WL_EVENT_READABLE,
413 weston_launcher_data,
414 launcher);
415 if (launcher->source == NULL) {
416 free(launcher);
417 return NULL;
418 }
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700419 } else {
David Herrmanncc5b2ed2013-10-22 00:28:09 +0200420 r = weston_logind_connect(&launcher->logind, compositor,
David Herrmann2ecb84a2014-12-30 14:33:22 +0100421 seat_id, tty, sync_drm);
David Herrmanncc5b2ed2013-10-22 00:28:09 +0200422 if (r < 0) {
423 launcher->logind = NULL;
424 if (geteuid() == 0) {
425 if (setup_tty(launcher, tty) == -1) {
426 free(launcher);
427 return NULL;
428 }
429 } else {
430 free(launcher);
431 return NULL;
432 }
433 }
Kristian Høgsberg1eb482d2013-09-17 22:15:37 -0700434 }
435
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -0700436 return launcher;
437}
438
439void
440weston_launcher_destroy(struct weston_launcher *launcher)
441{
Kristian Høgsbergd4c1cd72013-10-22 13:19:23 -0700442 if (launcher->logind) {
David Herrmanncc5b2ed2013-10-22 00:28:09 +0200443 weston_logind_destroy(launcher->logind);
Kristian Høgsbergd4c1cd72013-10-22 13:19:23 -0700444 } else if (launcher->fd != -1) {
Kristian Høgsberg3f495872013-09-18 23:00:17 -0700445 close(launcher->fd);
446 wl_event_source_remove(launcher->source);
447 } else {
448 weston_launcher_restore(launcher);
449 wl_event_source_remove(launcher->vt_source);
450 }
451
David Herrmanncc5b2ed2013-10-22 00:28:09 +0200452 if (launcher->tty >= 0)
453 close(launcher->tty);
454
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -0700455 free(launcher);
456}