blob: b6e989ff452a8ff1d3e6df655e223c6736611ca2 [file] [log] [blame]
Giulio Camuffobab996e2014-10-12 00:24:25 +03001/*
2 * Copyright © 2010-2011 Intel Corporation
3 * Copyright © 2008-2011 Kristian Høgsberg
4 * Copyright © 2012-2015 Collabora, Ltd.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28#include "config.h"
29
30#include <unistd.h>
31#include <signal.h>
32#include <errno.h>
33#include <dlfcn.h>
34#include <string.h>
35#include <sys/utsname.h>
36#include <sys/stat.h>
37#include <sys/wait.h>
38
39#ifdef HAVE_LIBUNWIND
40#define UNW_LOCAL_ONLY
41#include <libunwind.h>
42#endif
43
44#include "compositor.h"
45#include "../shared/os-compatibility.h"
46#include "../shared/helpers.h"
47#include "git-version.h"
48#include "version.h"
49
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -070050#include "compositor-drm.h"
Benoit Gschwind3c530942016-04-15 20:28:32 -070051#include "compositor-headless.h"
Benoit Gschwindbd573102016-04-22 17:05:26 +020052#include "compositor-rdp.h"
Benoit Gschwind934e89a2016-04-27 23:56:42 +020053#include "compositor-fbdev.h"
Benoit Gschwinde16acab2016-04-15 20:28:31 -070054#include "compositor-x11.h"
Benoit Gschwind3c530942016-04-15 20:28:32 -070055
Giulio Camuffobab996e2014-10-12 00:24:25 +030056static struct wl_list child_process_list;
57static struct weston_compositor *segv_compositor;
58
59static int
60sigchld_handler(int signal_number, void *data)
61{
62 struct weston_process *p;
63 int status;
64 pid_t pid;
65
66 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
67 wl_list_for_each(p, &child_process_list, link) {
68 if (p->pid == pid)
69 break;
70 }
71
72 if (&p->link == &child_process_list) {
73 weston_log("unknown child process exited\n");
74 continue;
75 }
76
77 wl_list_remove(&p->link);
78 p->cleanup(p, status);
79 }
80
81 if (pid < 0 && errno != ECHILD)
82 weston_log("waitpid error %m\n");
83
84 return 1;
85}
86
87#ifdef HAVE_LIBUNWIND
88
89static void
90print_backtrace(void)
91{
92 unw_cursor_t cursor;
93 unw_context_t context;
94 unw_word_t off;
95 unw_proc_info_t pip;
96 int ret, i = 0;
97 char procname[256];
98 const char *filename;
99 Dl_info dlinfo;
100
101 pip.unwind_info = NULL;
102 ret = unw_getcontext(&context);
103 if (ret) {
104 weston_log("unw_getcontext: %d\n", ret);
105 return;
106 }
107
108 ret = unw_init_local(&cursor, &context);
109 if (ret) {
110 weston_log("unw_init_local: %d\n", ret);
111 return;
112 }
113
114 ret = unw_step(&cursor);
115 while (ret > 0) {
116 ret = unw_get_proc_info(&cursor, &pip);
117 if (ret) {
118 weston_log("unw_get_proc_info: %d\n", ret);
119 break;
120 }
121
122 ret = unw_get_proc_name(&cursor, procname, 256, &off);
123 if (ret && ret != -UNW_ENOMEM) {
124 if (ret != -UNW_EUNSPEC)
125 weston_log("unw_get_proc_name: %d\n", ret);
126 procname[0] = '?';
127 procname[1] = 0;
128 }
129
130 if (dladdr((void *)(pip.start_ip + off), &dlinfo) && dlinfo.dli_fname &&
131 *dlinfo.dli_fname)
132 filename = dlinfo.dli_fname;
133 else
134 filename = "?";
135
136 weston_log("%u: %s (%s%s+0x%x) [%p]\n", i++, filename, procname,
137 ret == -UNW_ENOMEM ? "..." : "", (int)off, (void *)(pip.start_ip + off));
138
139 ret = unw_step(&cursor);
140 if (ret < 0)
141 weston_log("unw_step: %d\n", ret);
142 }
143}
144
145#else
146
147static void
148print_backtrace(void)
149{
150 void *buffer[32];
151 int i, count;
152 Dl_info info;
153
154 count = backtrace(buffer, ARRAY_LENGTH(buffer));
155 for (i = 0; i < count; i++) {
156 dladdr(buffer[i], &info);
157 weston_log(" [%016lx] %s (%s)\n",
158 (long) buffer[i],
159 info.dli_sname ? info.dli_sname : "--",
160 info.dli_fname);
161 }
162}
163
164#endif
165
166WL_EXPORT void
167weston_watch_process(struct weston_process *process)
168{
169 wl_list_insert(&child_process_list, &process->link);
170}
171
172static void
173log_uname(void)
174{
175 struct utsname usys;
176
177 uname(&usys);
178
179 weston_log("OS: %s, %s, %s, %s\n", usys.sysname, usys.release,
180 usys.version, usys.machine);
181}
182
183static const char xdg_error_message[] =
184 "fatal: environment variable XDG_RUNTIME_DIR is not set.\n";
185
186static const char xdg_wrong_message[] =
187 "fatal: environment variable XDG_RUNTIME_DIR\n"
188 "is set to \"%s\", which is not a directory.\n";
189
190static const char xdg_wrong_mode_message[] =
191 "warning: XDG_RUNTIME_DIR \"%s\" is not configured\n"
192 "correctly. Unix access mode must be 0700 (current mode is %o),\n"
193 "and must be owned by the user (current owner is UID %d).\n";
194
195static const char xdg_detail_message[] =
196 "Refer to your distribution on how to get it, or\n"
197 "http://www.freedesktop.org/wiki/Specifications/basedir-spec\n"
198 "on how to implement it.\n";
199
200static void
201verify_xdg_runtime_dir(void)
202{
203 char *dir = getenv("XDG_RUNTIME_DIR");
204 struct stat s;
205
206 if (!dir) {
207 weston_log(xdg_error_message);
208 weston_log_continue(xdg_detail_message);
209 exit(EXIT_FAILURE);
210 }
211
212 if (stat(dir, &s) || !S_ISDIR(s.st_mode)) {
213 weston_log(xdg_wrong_message, dir);
214 weston_log_continue(xdg_detail_message);
215 exit(EXIT_FAILURE);
216 }
217
218 if ((s.st_mode & 0777) != 0700 || s.st_uid != getuid()) {
219 weston_log(xdg_wrong_mode_message,
220 dir, s.st_mode & 0777, s.st_uid);
221 weston_log_continue(xdg_detail_message);
222 }
223}
224
225static int
226usage(int error_code)
227{
228 fprintf(stderr,
229 "Usage: weston [OPTIONS]\n\n"
230 "This is weston version " VERSION ", the Wayland reference compositor.\n"
231 "Weston supports multiple backends, and depending on which backend is in use\n"
232 "different options will be accepted.\n\n"
233
234
235 "Core options:\n\n"
236 " --version\t\tPrint weston version\n"
237 " -B, --backend=MODULE\tBackend module, one of\n"
238#if defined(BUILD_DRM_COMPOSITOR)
239 "\t\t\t\tdrm-backend.so\n"
240#endif
241#if defined(BUILD_FBDEV_COMPOSITOR)
242 "\t\t\t\tfbdev-backend.so\n"
243#endif
Dawid Gajownik71f57042015-07-31 17:39:00 -0300244#if defined(BUILD_HEADLESS_COMPOSITOR)
245 "\t\t\t\theadless-backend.so\n"
Giulio Camuffobab996e2014-10-12 00:24:25 +0300246#endif
247#if defined(BUILD_RDP_COMPOSITOR)
248 "\t\t\t\trdp-backend.so\n"
249#endif
Giulio Camuffobab996e2014-10-12 00:24:25 +0300250#if defined(BUILD_RPI_COMPOSITOR) && defined(HAVE_BCM_HOST)
251 "\t\t\t\trpi-backend.so\n"
252#endif
Dawid Gajownik71f57042015-07-31 17:39:00 -0300253#if defined(BUILD_WAYLAND_COMPOSITOR)
254 "\t\t\t\twayland-backend.so\n"
255#endif
256#if defined(BUILD_X11_COMPOSITOR)
257 "\t\t\t\tx11-backend.so\n"
258#endif
Giulio Camuffobab996e2014-10-12 00:24:25 +0300259 " --shell=MODULE\tShell module, defaults to desktop-shell.so\n"
260 " -S, --socket=NAME\tName of socket to listen on\n"
261 " -i, --idle-time=SECS\tIdle time in seconds\n"
262 " --modules\t\tLoad the comma-separated list of modules\n"
263 " --log=FILE\t\tLog to the given file\n"
264 " -c, --config=FILE\tConfig file to load, defaults to weston.ini\n"
265 " --no-config\t\tDo not read weston.ini\n"
266 " -h, --help\t\tThis help message\n\n");
267
268#if defined(BUILD_DRM_COMPOSITOR)
269 fprintf(stderr,
270 "Options for drm-backend.so:\n\n"
271 " --connector=ID\tBring up only this connector\n"
272 " --seat=SEAT\t\tThe seat that weston should run on\n"
273 " --tty=TTY\t\tThe tty to use\n"
274 " --use-pixman\t\tUse the pixman (CPU) renderer\n"
275 " --current-mode\tPrefer current KMS mode over EDID preferred mode\n\n");
276#endif
277
278#if defined(BUILD_FBDEV_COMPOSITOR)
279 fprintf(stderr,
280 "Options for fbdev-backend.so:\n\n"
281 " --tty=TTY\t\tThe tty to use\n"
282 " --device=DEVICE\tThe framebuffer device to use\n"
283 " --use-gl\t\tUse the GL renderer\n\n");
284#endif
285
Dawid Gajownik71f57042015-07-31 17:39:00 -0300286#if defined(BUILD_HEADLESS_COMPOSITOR)
Giulio Camuffobab996e2014-10-12 00:24:25 +0300287 fprintf(stderr,
Dawid Gajownik71f57042015-07-31 17:39:00 -0300288 "Options for headless-backend.so:\n\n"
289 " --width=WIDTH\t\tWidth of memory surface\n"
290 " --height=HEIGHT\tHeight of memory surface\n"
Giulio Camuffobab996e2014-10-12 00:24:25 +0300291 " --transform=TR\tThe output transformation, TR is one of:\n"
292 "\tnormal 90 180 270 flipped flipped-90 flipped-180 flipped-270\n"
Dawid Gajownik71f57042015-07-31 17:39:00 -0300293 " --use-pixman\t\tUse the pixman (CPU) renderer (default: no rendering)\n\n");
Giulio Camuffobab996e2014-10-12 00:24:25 +0300294#endif
295
296#if defined(BUILD_RDP_COMPOSITOR)
297 fprintf(stderr,
298 "Options for rdp-backend.so:\n\n"
299 " --width=WIDTH\t\tWidth of desktop\n"
300 " --height=HEIGHT\tHeight of desktop\n"
Dawid Gajownikd99a0502015-07-31 14:49:57 -0300301 " --env-socket\t\tUse socket defined in RDP_FD env variable as peer connection\n"
Giulio Camuffobab996e2014-10-12 00:24:25 +0300302 " --address=ADDR\tThe address to bind\n"
303 " --port=PORT\t\tThe port to listen on\n"
304 " --no-clients-resize\tThe RDP peers will be forced to the size of the desktop\n"
305 " --rdp4-key=FILE\tThe file containing the key for RDP4 encryption\n"
306 " --rdp-tls-cert=FILE\tThe file containing the certificate for TLS encryption\n"
307 " --rdp-tls-key=FILE\tThe file containing the private key for TLS encryption\n"
308 "\n");
309#endif
310
Dawid Gajownik71f57042015-07-31 17:39:00 -0300311#if defined(BUILD_RPI_COMPOSITOR) && defined(HAVE_BCM_HOST)
Giulio Camuffobab996e2014-10-12 00:24:25 +0300312 fprintf(stderr,
Dawid Gajownik71f57042015-07-31 17:39:00 -0300313 "Options for rpi-backend.so:\n\n"
314 " --tty=TTY\t\tThe tty to use\n"
315 " --single-buffer\tUse single-buffered Dispmanx elements.\n"
Giulio Camuffobab996e2014-10-12 00:24:25 +0300316 " --transform=TR\tThe output transformation, TR is one of:\n"
317 "\tnormal 90 180 270 flipped flipped-90 flipped-180 flipped-270\n"
Dawid Gajownik71f57042015-07-31 17:39:00 -0300318 " --opaque-regions\tEnable support for opaque regions, can be "
319 "very slow without support in the GPU firmware.\n"
320 "\n");
321#endif
322
323#if defined(BUILD_WAYLAND_COMPOSITOR)
324 fprintf(stderr,
325 "Options for wayland-backend.so:\n\n"
326 " --width=WIDTH\t\tWidth of Wayland surface\n"
327 " --height=HEIGHT\tHeight of Wayland surface\n"
328 " --scale=SCALE\t\tScale factor of output\n"
329 " --fullscreen\t\tRun in fullscreen mode\n"
330 " --use-pixman\t\tUse the pixman (CPU) renderer\n"
331 " --output-count=COUNT\tCreate multiple outputs\n"
332 " --sprawl\t\tCreate one fullscreen output for every parent output\n"
333 " --display=DISPLAY\tWayland display to connect to\n\n");
334#endif
335
336#if defined(BUILD_X11_COMPOSITOR)
337 fprintf(stderr,
338 "Options for x11-backend.so:\n\n"
339 " --width=WIDTH\t\tWidth of X window\n"
340 " --height=HEIGHT\tHeight of X window\n"
341 " --scale=SCALE\t\tScale factor of output\n"
342 " --fullscreen\t\tRun in fullscreen mode\n"
343 " --use-pixman\t\tUse the pixman (CPU) renderer\n"
344 " --output-count=COUNT\tCreate multiple outputs\n"
345 " --no-input\t\tDont create input devices\n\n");
Giulio Camuffobab996e2014-10-12 00:24:25 +0300346#endif
347
348 exit(error_code);
349}
350
351static int on_term_signal(int signal_number, void *data)
352{
353 struct wl_display *display = data;
354
355 weston_log("caught signal %d\n", signal_number);
356 wl_display_terminate(display);
357
358 return 1;
359}
360
361static void
362on_caught_signal(int s, siginfo_t *siginfo, void *context)
363{
364 /* This signal handler will do a best-effort backtrace, and
365 * then call the backend restore function, which will switch
366 * back to the vt we launched from or ungrab X etc and then
367 * raise SIGTRAP. If we run weston under gdb from X or a
368 * different vt, and tell gdb "handle *s* nostop", this
369 * will allow weston to switch back to gdb on crash and then
370 * gdb will catch the crash with SIGTRAP.*/
371
372 weston_log("caught signal: %d\n", s);
373
374 print_backtrace();
375
376 segv_compositor->backend->restore(segv_compositor);
377
378 raise(SIGTRAP);
379}
380
381static void
382catch_signals(void)
383{
384 struct sigaction action;
385
386 action.sa_flags = SA_SIGINFO | SA_RESETHAND;
387 action.sa_sigaction = on_caught_signal;
388 sigemptyset(&action.sa_mask);
389 sigaction(SIGSEGV, &action, NULL);
390 sigaction(SIGABRT, &action, NULL);
391}
392
393static const char *
394clock_name(clockid_t clk_id)
395{
396 static const char *names[] = {
397 [CLOCK_REALTIME] = "CLOCK_REALTIME",
398 [CLOCK_MONOTONIC] = "CLOCK_MONOTONIC",
399 [CLOCK_MONOTONIC_RAW] = "CLOCK_MONOTONIC_RAW",
400 [CLOCK_REALTIME_COARSE] = "CLOCK_REALTIME_COARSE",
401 [CLOCK_MONOTONIC_COARSE] = "CLOCK_MONOTONIC_COARSE",
Derek Foreman32838c92015-06-29 13:20:34 -0500402#ifdef CLOCK_BOOTTIME
Giulio Camuffobab996e2014-10-12 00:24:25 +0300403 [CLOCK_BOOTTIME] = "CLOCK_BOOTTIME",
Derek Foreman32838c92015-06-29 13:20:34 -0500404#endif
Giulio Camuffobab996e2014-10-12 00:24:25 +0300405 };
406
407 if (clk_id < 0 || (unsigned)clk_id >= ARRAY_LENGTH(names))
408 return "unknown";
409
410 return names[clk_id];
411}
412
413static const struct {
414 uint32_t bit; /* enum weston_capability */
415 const char *desc;
416} capability_strings[] = {
417 { WESTON_CAP_ROTATION_ANY, "arbitrary surface rotation:" },
418 { WESTON_CAP_CAPTURE_YFLIP, "screen capture uses y-flip:" },
419};
420
421static void
422weston_compositor_log_capabilities(struct weston_compositor *compositor)
423{
424 unsigned i;
425 int yes;
426
427 weston_log("Compositor capabilities:\n");
428 for (i = 0; i < ARRAY_LENGTH(capability_strings); i++) {
429 yes = compositor->capabilities & capability_strings[i].bit;
430 weston_log_continue(STAMP_SPACE "%s %s\n",
431 capability_strings[i].desc,
432 yes ? "yes" : "no");
433 }
434
435 weston_log_continue(STAMP_SPACE "presentation clock: %s, id %d\n",
436 clock_name(compositor->presentation_clock),
437 compositor->presentation_clock);
438}
439
440static void
441handle_primary_client_destroyed(struct wl_listener *listener, void *data)
442{
443 struct wl_client *client = data;
444
445 weston_log("Primary client died. Closing...\n");
446
447 wl_display_terminate(wl_client_get_display(client));
448}
449
450static int
451weston_create_listening_socket(struct wl_display *display, const char *socket_name)
452{
453 if (socket_name) {
454 if (wl_display_add_socket(display, socket_name)) {
455 weston_log("fatal: failed to add socket: %m\n");
456 return -1;
457 }
458 } else {
459 socket_name = wl_display_add_socket_auto(display);
460 if (!socket_name) {
461 weston_log("fatal: failed to add socket: %m\n");
462 return -1;
463 }
464 }
465
466 setenv("WAYLAND_DISPLAY", socket_name, 1);
467
468 return 0;
469}
470
471static int
472load_modules(struct weston_compositor *ec, const char *modules,
473 int *argc, char *argv[])
474{
475 const char *p, *end;
476 char buffer[256];
477 int (*module_init)(struct weston_compositor *ec,
478 int *argc, char *argv[]);
479
480 if (modules == NULL)
481 return 0;
482
483 p = modules;
484 while (*p) {
485 end = strchrnul(p, ',');
486 snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
487 module_init = weston_load_module(buffer, "module_init");
488 if (!module_init)
489 return -1;
490 if (module_init(ec, argc, argv) < 0)
491 return -1;
492 p = end;
493 while (*p == ',')
494 p++;
495
496 }
497
498 return 0;
499}
500
501static int
502weston_compositor_init_config(struct weston_compositor *ec,
503 struct weston_config *config)
504{
505 struct xkb_rule_names xkb_names;
506 struct weston_config_section *s;
507 int repaint_msec;
Bob Ham91880f12016-01-12 10:21:47 +0000508 int vt_switching;
Giulio Camuffobab996e2014-10-12 00:24:25 +0300509
510 s = weston_config_get_section(config, "keyboard", NULL, NULL);
511 weston_config_section_get_string(s, "keymap_rules",
512 (char **) &xkb_names.rules, NULL);
513 weston_config_section_get_string(s, "keymap_model",
514 (char **) &xkb_names.model, NULL);
515 weston_config_section_get_string(s, "keymap_layout",
516 (char **) &xkb_names.layout, NULL);
517 weston_config_section_get_string(s, "keymap_variant",
518 (char **) &xkb_names.variant, NULL);
519 weston_config_section_get_string(s, "keymap_options",
520 (char **) &xkb_names.options, NULL);
521
522 if (weston_compositor_xkb_init(ec, &xkb_names) < 0)
523 return -1;
524
525 weston_config_section_get_int(s, "repeat-rate",
526 &ec->kb_repeat_rate, 40);
527 weston_config_section_get_int(s, "repeat-delay",
528 &ec->kb_repeat_delay, 400);
529
Bob Ham91880f12016-01-12 10:21:47 +0000530 weston_config_section_get_bool(s, "vt-switching",
531 &vt_switching, true);
532 ec->vt_switching = vt_switching;
533
Giulio Camuffobab996e2014-10-12 00:24:25 +0300534 s = weston_config_get_section(config, "core", NULL, NULL);
535 weston_config_section_get_int(s, "repaint-window", &repaint_msec,
536 ec->repaint_msec);
537 if (repaint_msec < -10 || repaint_msec > 1000) {
538 weston_log("Invalid repaint_window value in config: %d\n",
539 repaint_msec);
540 } else {
541 ec->repaint_msec = repaint_msec;
542 }
543 weston_log("Output repaint window is %d ms maximum.\n",
544 ec->repaint_msec);
545
546 return 0;
547}
548
549static char *
550weston_choose_default_backend(void)
551{
552 char *backend = NULL;
553
554 if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET"))
555 backend = strdup("wayland-backend.so");
556 else if (getenv("DISPLAY"))
557 backend = strdup("x11-backend.so");
558 else
559 backend = strdup(WESTON_NATIVE_BACKEND);
560
561 return backend;
562}
563
564static const struct { const char *name; uint32_t token; } transforms[] = {
565 { "normal", WL_OUTPUT_TRANSFORM_NORMAL },
566 { "90", WL_OUTPUT_TRANSFORM_90 },
567 { "180", WL_OUTPUT_TRANSFORM_180 },
568 { "270", WL_OUTPUT_TRANSFORM_270 },
569 { "flipped", WL_OUTPUT_TRANSFORM_FLIPPED },
570 { "flipped-90", WL_OUTPUT_TRANSFORM_FLIPPED_90 },
571 { "flipped-180", WL_OUTPUT_TRANSFORM_FLIPPED_180 },
572 { "flipped-270", WL_OUTPUT_TRANSFORM_FLIPPED_270 },
573};
574
575WL_EXPORT int
576weston_parse_transform(const char *transform, uint32_t *out)
577{
578 unsigned int i;
579
580 for (i = 0; i < ARRAY_LENGTH(transforms); i++)
581 if (strcmp(transforms[i].name, transform) == 0) {
582 *out = transforms[i].token;
583 return 0;
584 }
585
586 *out = WL_OUTPUT_TRANSFORM_NORMAL;
587 return -1;
588}
589
590WL_EXPORT const char *
591weston_transform_to_string(uint32_t output_transform)
592{
593 unsigned int i;
594
595 for (i = 0; i < ARRAY_LENGTH(transforms); i++)
596 if (transforms[i].token == output_transform)
597 return transforms[i].name;
598
599 return "<illegal value>";
600}
601
602static int
603load_configuration(struct weston_config **config, int32_t noconfig,
604 const char *config_file)
605{
606 const char *file = "weston.ini";
607 const char *full_path;
608
609 *config = NULL;
610
611 if (config_file)
612 file = config_file;
613
614 if (noconfig == 0)
615 *config = weston_config_parse(file);
616
617 if (*config) {
618 full_path = weston_config_get_full_path(*config);
619
620 weston_log("Using config file '%s'\n", full_path);
621 setenv(WESTON_CONFIG_FILE_ENV_VAR, full_path, 1);
622
623 return 0;
624 }
625
626 if (config_file && noconfig == 0) {
627 weston_log("fatal: error opening or reading config file"
628 " '%s'.\n", config_file);
629
630 return -1;
631 }
632
633 weston_log("Starting with no config file.\n");
634 setenv(WESTON_CONFIG_FILE_ENV_VAR, "", 1);
635
636 return 0;
637}
638
639static void
640handle_exit(struct weston_compositor *c)
641{
642 wl_display_terminate(c->wl_display);
643}
644
Giulio Camuffo43008c72015-10-17 19:24:15 +0300645/* Temporary function to be removed when all backends are converted. */
646static int
647load_backend_old(struct weston_compositor *compositor, const char *backend,
648 int *argc, char **argv, struct weston_config *wc)
649{
650 int (*backend_init)(struct weston_compositor *c,
651 int *argc, char *argv[],
652 struct weston_config *config,
653 struct weston_backend_config *config_base);
654
655 backend_init = weston_load_module(backend, "backend_init");
656 if (!backend_init)
657 return -1;
658
659 return backend_init(compositor, argc, argv, wc, NULL);
660}
661
Bryce Harrington98ab08b2016-04-15 20:28:36 -0700662/** Main module call-point for backends.
663 *
664 * All backends should use this routine to access their init routine.
665 * Backends may subclass weston_backend_config to add their own
666 * configuration data, setting the major/minor version in config_base
667 * accordingly.
668 *
669 * The config_base object should be treated as temporary, and any data
670 * copied out of it by backend_init before returning. The load_backend_new
671 * callers may then free the config_base object.
672 *
673 * NOTE: This is a temporary function intended to eventually be replaced
674 * by weston_compositor_load_backend().
675 */
Bryce Harrington6ca25b32016-04-15 20:28:27 -0700676static int
677load_backend_new(struct weston_compositor *compositor, const char *backend,
678 struct weston_backend_config *config_base)
679{
680 int (*backend_init)(struct weston_compositor *c,
681 int *argc, char *argv[],
682 struct weston_config *config,
683 struct weston_backend_config *config_base);
684
685 backend_init = weston_load_module(backend, "backend_init");
686 if (!backend_init)
687 return -1;
688
689 return backend_init(compositor, NULL, NULL, NULL, config_base);
690}
691
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -0700692static enum weston_drm_backend_output_mode
693drm_configure_output(struct weston_compositor *c,
694 bool use_current_mode,
695 const char *name,
696 struct weston_drm_backend_output_config *config)
697{
698 struct weston_config *wc = weston_compositor_get_user_data(c);
699 struct weston_config_section *section;
700 char *s;
701 int scale;
702 enum weston_drm_backend_output_mode mode =
703 WESTON_DRM_BACKEND_OUTPUT_PREFERRED;
704
705 section = weston_config_get_section(wc, "output", "name", name);
706 weston_config_section_get_string(section, "mode", &s, "preferred");
707 if (strcmp(s, "off") == 0) {
708 free(s);
709 return WESTON_DRM_BACKEND_OUTPUT_OFF;
710 }
711
712 if (use_current_mode || strcmp(s, "current") == 0) {
713 mode = WESTON_DRM_BACKEND_OUTPUT_CURRENT;
714 } else if (strcmp(s, "preferred") != 0) {
715 config->modeline = s;
716 s = NULL;
717 }
718 free(s);
719
720 weston_config_section_get_int(section, "scale", &scale, 1);
721 config->base.scale = scale >= 1 ? scale : 1;
722 weston_config_section_get_string(section, "transform", &s, "normal");
723 if (weston_parse_transform(s, &config->base.transform) < 0)
724 weston_log("Invalid transform \"%s\" for output %s\n",
725 s, name);
726 free(s);
727
728 weston_config_section_get_string(section,
729 "gbm-format", &config->gbm_format, NULL);
730 weston_config_section_get_string(section, "seat", &config->seat, "");
731 return mode;
732}
733
734static int
735load_drm_backend(struct weston_compositor *c, const char *backend,
736 int *argc, char **argv, struct weston_config *wc)
737{
738 struct weston_drm_backend_config config = {{ 0, }};
739 struct weston_config_section *section;
740 int ret = 0;
741
742 const struct weston_option options[] = {
743 { WESTON_OPTION_INTEGER, "connector", 0, &config.connector },
744 { WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
745 { WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
746 { WESTON_OPTION_BOOLEAN, "current-mode", 0, &config.use_current_mode },
747 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
748 };
749
750 parse_options(options, ARRAY_LENGTH(options), argc, argv);
751
752 section = weston_config_get_section(wc, "core", NULL, NULL);
753 weston_config_section_get_string(section,
754 "gbm-format", &config.gbm_format,
755 NULL);
756
757 config.base.struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION;
758 config.base.struct_size = sizeof(struct weston_drm_backend_config);
759 config.configure_output = drm_configure_output;
760
761 ret = load_backend_new(c, backend, &config.base);
762
763 free(config.gbm_format);
764 free(config.seat_id);
765
766 return ret;
767}
768
Giulio Camuffo43008c72015-10-17 19:24:15 +0300769static int
Benoit Gschwind3c530942016-04-15 20:28:32 -0700770load_headless_backend(struct weston_compositor *c, char const * backend,
771 int *argc, char **argv, struct weston_config *wc)
772{
773 struct weston_headless_backend_config config = {{ 0, }};
774 int ret = 0;
Benoit Gschwind2da6d0c2016-04-29 15:21:54 +0200775 char *transform = NULL;
Benoit Gschwind3c530942016-04-15 20:28:32 -0700776
777 config.width = 1024;
778 config.height = 640;
779
780 const struct weston_option options[] = {
781 { WESTON_OPTION_INTEGER, "width", 0, &config.width },
782 { WESTON_OPTION_INTEGER, "height", 0, &config.height },
783 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
784 { WESTON_OPTION_STRING, "transform", 0, &transform },
785 };
786
787 parse_options(options, ARRAY_LENGTH(options), argc, argv);
788
Benoit Gschwind2da6d0c2016-04-29 15:21:54 +0200789 config.transform = WL_OUTPUT_TRANSFORM_NORMAL;
790 if (transform) {
791 if (weston_parse_transform(transform, &config.transform) < 0)
792 weston_log("Invalid transform \"%s\"\n", transform);
793 free(transform);
794 }
Benoit Gschwind3c530942016-04-15 20:28:32 -0700795
796 config.base.struct_version = WESTON_HEADLESS_BACKEND_CONFIG_VERSION;
797 config.base.struct_size = sizeof(struct weston_headless_backend_config);
798
799 /* load the actual wayland backend and configure it */
800 ret = load_backend_new(c, backend, &config.base);
801
802 return ret;
803}
804
Benoit Gschwindbd573102016-04-22 17:05:26 +0200805static void
806weston_rdp_backend_config_init(struct weston_rdp_backend_config *config)
807{
808 config->base.struct_version = WESTON_RDP_BACKEND_CONFIG_VERSION;
809 config->base.struct_size = sizeof(struct weston_rdp_backend_config);
810
811 config->width = 640;
812 config->height = 480;
813 config->bind_address = NULL;
814 config->port = 3389;
815 config->rdp_key = NULL;
816 config->server_cert = NULL;
817 config->server_key = NULL;
818 config->env_socket = 0;
819 config->no_clients_resize = 0;
820}
821
822static int
823load_rdp_backend(struct weston_compositor *c, char const * backend,
824 int *argc, char *argv[], struct weston_config *wc)
825{
826 struct weston_rdp_backend_config config = {{ 0, }};
827 int ret = 0;
828
829 weston_rdp_backend_config_init(&config);
830
831 const struct weston_option rdp_options[] = {
832 { WESTON_OPTION_BOOLEAN, "env-socket", 0, &config.env_socket },
833 { WESTON_OPTION_INTEGER, "width", 0, &config.width },
834 { WESTON_OPTION_INTEGER, "height", 0, &config.height },
835 { WESTON_OPTION_STRING, "address", 0, &config.bind_address },
836 { WESTON_OPTION_INTEGER, "port", 0, &config.port },
837 { WESTON_OPTION_BOOLEAN, "no-clients-resize", 0, &config.no_clients_resize },
838 { WESTON_OPTION_STRING, "rdp4-key", 0, &config.rdp_key },
839 { WESTON_OPTION_STRING, "rdp-tls-cert", 0, &config.server_cert },
840 { WESTON_OPTION_STRING, "rdp-tls-key", 0, &config.server_key }
841 };
842
843 parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv);
844
845 ret = load_backend_new(c, backend, &config.base);
846
847 free(config.bind_address);
848 free(config.rdp_key);
849 free(config.server_cert);
850 free(config.server_key);
851 return ret;
852}
853
Benoit Gschwind3c530942016-04-15 20:28:32 -0700854static int
Benoit Gschwind934e89a2016-04-27 23:56:42 +0200855load_fbdev_backend(struct weston_compositor *c, char const * backend,
856 int *argc, char **argv, struct weston_config *wc)
857{
858 struct weston_fbdev_backend_config config = {{ 0, }};
859 struct weston_config_section *section;
860 char *s = NULL;
861 int ret = 0;
862
863 const struct weston_option fbdev_options[] = {
864 { WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
865 { WESTON_OPTION_STRING, "device", 0, &config.device },
866 { WESTON_OPTION_BOOLEAN, "use-gl", 0, &config.use_gl },
867 };
868
869 parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv);
870
871 if (!config.device)
872 config.device = strdup("/dev/fb0");
873
874 section = weston_config_get_section(wc, "output", "name", "fbdev");
875 weston_config_section_get_string(section, "transform", &s, "normal");
876 if (weston_parse_transform(s, &config.output_transform) < 0)
877 weston_log("Invalid transform \"%s\" for output fbdev\n", s);
878 free(s);
879
880 config.base.struct_version = WESTON_FBDEV_BACKEND_CONFIG_VERSION;
881 config.base.struct_size = sizeof(struct weston_fbdev_backend_config);
882
883 /* load the actual wayland backend and configure it */
884 ret = load_backend_new(c, backend, &config.base);
885
886 free(config.device);
Benoit Gschwinde16acab2016-04-15 20:28:31 -0700887
888 return ret;
889}
890
891static int
892weston_x11_backend_config_append_output_config(struct weston_x11_backend_config *config,
893 struct weston_x11_backend_output_config *output_config) {
894 struct weston_x11_backend_output_config *new_outputs;
895
896 new_outputs = realloc(config->outputs, (config->num_outputs+1) *
897 sizeof(struct weston_x11_backend_output_config));
898 if (new_outputs == NULL)
899 return -1;
900
901 config->outputs = new_outputs;
902 config->outputs[config->num_outputs].width = output_config->width;
903 config->outputs[config->num_outputs].height = output_config->height;
904 config->outputs[config->num_outputs].transform = output_config->transform;
905 config->outputs[config->num_outputs].scale = output_config->scale;
906 config->outputs[config->num_outputs].name = strdup(output_config->name);
907 config->num_outputs++;
908
909 return 0;
910}
911
912static int
913load_x11_backend(struct weston_compositor *c, char const * backend,
914 int *argc, char **argv, struct weston_config *wc)
915{
916 struct weston_x11_backend_output_config default_output;
917 struct weston_x11_backend_config config = {{ 0, }};
918 struct weston_config_section *section;
919 int ret = 0;
920 int option_width = 0;
921 int option_height = 0;
922 int option_scale = 0;
923 int option_count = 1;
924 int output_count = 0;
925 char const *section_name;
926 int i;
927 uint32_t j;
928
929 const struct weston_option options[] = {
930 { WESTON_OPTION_INTEGER, "width", 0, &option_width },
931 { WESTON_OPTION_INTEGER, "height", 0, &option_height },
932 { WESTON_OPTION_INTEGER, "scale", 0, &option_scale },
933 { WESTON_OPTION_BOOLEAN, "fullscreen", 'f', &config.fullscreen },
934 { WESTON_OPTION_INTEGER, "output-count", 0, &option_count },
935 { WESTON_OPTION_BOOLEAN, "no-input", 0, &config.no_input },
936 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
937 };
938
939 parse_options(options, ARRAY_LENGTH(options), argc, argv);
940
941 section = NULL;
942 while (weston_config_next_section(wc, &section, &section_name)) {
943 struct weston_x11_backend_output_config current_output = { 0, };
944 char *t;
945 char *mode;
946
947 if (strcmp(section_name, "output") != 0) {
948 continue;
949 }
950
951 weston_config_section_get_string(section, "name", &current_output.name, NULL);
952 if (current_output.name == NULL || current_output.name[0] != 'X') {
953 free(current_output.name);
954 continue;
955 }
956
957 weston_config_section_get_string(section, "mode", &mode, "1024x600");
958 if (sscanf(mode, "%dx%d", &current_output.width,
959 &current_output.height) != 2) {
960 weston_log("Invalid mode \"%s\" for output %s\n",
961 mode, current_output.name);
962 current_output.width = 1024;
963 current_output.height = 600;
964 }
965 free(mode);
966 if (current_output.width < 1)
967 current_output.width = 1024;
968 if (current_output.height < 1)
969 current_output.height = 600;
970 if (option_width)
971 current_output.width = option_width;
972 if (option_height)
973 current_output.height = option_height;
974
975 weston_config_section_get_int(section, "scale", &current_output.scale, 1);
976 if (option_scale)
977 current_output.scale = option_scale;
978
979 weston_config_section_get_string(section,
980 "transform", &t, "normal");
981 if (weston_parse_transform(t, &current_output.transform) < 0)
982 weston_log("Invalid transform \"%s\" for output %s\n",
983 t, current_output.name);
984 free(t);
985
986 if (weston_x11_backend_config_append_output_config(&config, &current_output) < 0) {
987 ret = -1;
988 goto out;
989 }
990
991 output_count++;
Bryce Harringtonaa258982016-05-03 01:34:23 -0700992 if (output_count >= option_count)
Benoit Gschwinde16acab2016-04-15 20:28:31 -0700993 break;
994 }
995
996 default_output.name = NULL;
997 default_output.width = option_width ? option_width : 1024;
998 default_output.height = option_height ? option_height : 600;
999 default_output.scale = option_scale ? option_scale : 1;
1000 default_output.transform = WL_OUTPUT_TRANSFORM_NORMAL;
1001
1002 for (i = output_count; i < option_count; i++) {
1003 if (asprintf(&default_output.name, "screen%d", i) < 0) {
1004 ret = -1;
1005 goto out;
1006 }
1007
1008 if (weston_x11_backend_config_append_output_config(&config, &default_output) < 0) {
1009 ret = -1;
1010 free(default_output.name);
1011 goto out;
1012 }
1013 free(default_output.name);
1014 }
1015
1016 config.base.struct_version = WESTON_X11_BACKEND_CONFIG_VERSION;
1017 config.base.struct_size = sizeof(struct weston_x11_backend_config);
1018
1019 /* load the actual backend and configure it */
1020 ret = load_backend_new(c, backend, &config.base);
1021
1022out:
1023 for (j = 0; j < config.num_outputs; ++j)
1024 free(config.outputs[j].name);
1025 free(config.outputs);
1026
Benoit Gschwind934e89a2016-04-27 23:56:42 +02001027 return ret;
1028}
1029
1030static int
Giulio Camuffo43008c72015-10-17 19:24:15 +03001031load_backend(struct weston_compositor *compositor, const char *backend,
1032 int *argc, char **argv, struct weston_config *config)
1033{
Benoit Gschwind3c530942016-04-15 20:28:32 -07001034 if (strstr(backend, "headless-backend.so"))
1035 return load_headless_backend(compositor, backend, argc, argv, config);
Benoit Gschwindbd573102016-04-22 17:05:26 +02001036 else if (strstr(backend, "rdp-backend.so"))
1037 return load_rdp_backend(compositor, backend, argc, argv, config);
Benoit Gschwind934e89a2016-04-27 23:56:42 +02001038 else if (strstr(backend, "fbdev-backend.so"))
1039 return load_fbdev_backend(compositor, backend, argc, argv, config);
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -07001040 else if (strstr(backend, "drm-backend.so"))
1041 return load_drm_backend(compositor, backend, argc, argv, config);
Benoit Gschwinde16acab2016-04-15 20:28:31 -07001042 else if (strstr(backend, "x11-backend.so"))
1043 return load_x11_backend(compositor, backend, argc, argv, config);
Giulio Camuffo43008c72015-10-17 19:24:15 +03001044#if 0
Giulio Camuffo43008c72015-10-17 19:24:15 +03001045 else if (strstr(backend, "wayland-backend.so"))
1046 return load_wayland_backend(compositor, backend, argc, argv, config);
Giulio Camuffo43008c72015-10-17 19:24:15 +03001047 else if (strstr(backend, "rpi-backend.so"))
1048 return load_rpi_backend(compositor, backend, argc, argv, config);
Giulio Camuffo43008c72015-10-17 19:24:15 +03001049#endif
1050
1051 return load_backend_old(compositor, backend, argc, argv, config);
1052}
1053
Giulio Camuffobab996e2014-10-12 00:24:25 +03001054int main(int argc, char *argv[])
1055{
1056 int ret = EXIT_FAILURE;
1057 struct wl_display *display;
1058 struct weston_compositor *ec;
1059 struct wl_event_source *signals[4];
1060 struct wl_event_loop *loop;
Giulio Camuffobab996e2014-10-12 00:24:25 +03001061 int i, fd;
1062 char *backend = NULL;
1063 char *shell = NULL;
1064 char *modules = NULL;
1065 char *option_modules = NULL;
1066 char *log = NULL;
1067 char *server_socket = NULL, *end;
1068 int32_t idle_time = -1;
1069 int32_t help = 0;
1070 char *socket_name = NULL;
1071 int32_t version = 0;
1072 int32_t noconfig = 0;
1073 int32_t numlock_on;
1074 char *config_file = NULL;
1075 struct weston_config *config = NULL;
1076 struct weston_config_section *section;
1077 struct wl_client *primary_client;
1078 struct wl_listener primary_client_destroyed;
1079 struct weston_seat *seat;
1080
1081 const struct weston_option core_options[] = {
1082 { WESTON_OPTION_STRING, "backend", 'B', &backend },
1083 { WESTON_OPTION_STRING, "shell", 0, &shell },
1084 { WESTON_OPTION_STRING, "socket", 'S', &socket_name },
1085 { WESTON_OPTION_INTEGER, "idle-time", 'i', &idle_time },
1086 { WESTON_OPTION_STRING, "modules", 0, &option_modules },
1087 { WESTON_OPTION_STRING, "log", 0, &log },
1088 { WESTON_OPTION_BOOLEAN, "help", 'h', &help },
1089 { WESTON_OPTION_BOOLEAN, "version", 0, &version },
1090 { WESTON_OPTION_BOOLEAN, "no-config", 0, &noconfig },
1091 { WESTON_OPTION_STRING, "config", 'c', &config_file },
1092 };
1093
1094 parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv);
1095
1096 if (help)
1097 usage(EXIT_SUCCESS);
1098
1099 if (version) {
1100 printf(PACKAGE_STRING "\n");
1101 return EXIT_SUCCESS;
1102 }
1103
1104 weston_log_file_open(log);
1105
1106 weston_log("%s\n"
1107 STAMP_SPACE "%s\n"
1108 STAMP_SPACE "Bug reports to: %s\n"
1109 STAMP_SPACE "Build: %s\n",
1110 PACKAGE_STRING, PACKAGE_URL, PACKAGE_BUGREPORT,
1111 BUILD_ID);
1112 log_uname();
1113
1114 verify_xdg_runtime_dir();
1115
1116 display = wl_display_create();
1117
1118 loop = wl_display_get_event_loop(display);
1119 signals[0] = wl_event_loop_add_signal(loop, SIGTERM, on_term_signal,
1120 display);
1121 signals[1] = wl_event_loop_add_signal(loop, SIGINT, on_term_signal,
1122 display);
1123 signals[2] = wl_event_loop_add_signal(loop, SIGQUIT, on_term_signal,
1124 display);
1125
1126 wl_list_init(&child_process_list);
1127 signals[3] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler,
1128 NULL);
1129
1130 if (!signals[0] || !signals[1] || !signals[2] || !signals[3])
1131 goto out_signals;
1132
1133 if (load_configuration(&config, noconfig, config_file) < 0)
1134 goto out_signals;
1135
1136 section = weston_config_get_section(config, "core", NULL, NULL);
1137
1138 if (!backend) {
1139 weston_config_section_get_string(section, "backend", &backend,
1140 NULL);
1141 if (!backend)
1142 backend = weston_choose_default_backend();
1143 }
1144
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -07001145 ec = weston_compositor_create(display, config);
Giulio Camuffobab996e2014-10-12 00:24:25 +03001146 if (ec == NULL) {
1147 weston_log("fatal: failed to create compositor\n");
Giulio Camuffo3c241b12015-10-03 16:25:16 +03001148 goto out;
Giulio Camuffobab996e2014-10-12 00:24:25 +03001149 }
1150
1151 ec->config = config;
1152 if (weston_compositor_init_config(ec, config) < 0)
Giulio Camuffo3c241b12015-10-03 16:25:16 +03001153 goto out;
Giulio Camuffobab996e2014-10-12 00:24:25 +03001154
Giulio Camuffo43008c72015-10-17 19:24:15 +03001155 if (load_backend(ec, backend, &argc, argv, config) < 0) {
Giulio Camuffobab996e2014-10-12 00:24:25 +03001156 weston_log("fatal: failed to create compositor backend\n");
Giulio Camuffo3c241b12015-10-03 16:25:16 +03001157 goto out;
Giulio Camuffobab996e2014-10-12 00:24:25 +03001158 }
1159
1160 catch_signals();
1161 segv_compositor = ec;
1162
1163 if (idle_time < 0)
1164 weston_config_section_get_int(section, "idle-time", &idle_time, -1);
1165 if (idle_time < 0)
1166 idle_time = 300; /* default idle timeout, in seconds */
1167
1168 ec->idle_time = idle_time;
1169 ec->default_pointer_grab = NULL;
1170 ec->exit = handle_exit;
1171
1172 weston_compositor_log_capabilities(ec);
1173
1174 server_socket = getenv("WAYLAND_SERVER_SOCKET");
1175 if (server_socket) {
1176 weston_log("Running with single client\n");
1177 fd = strtol(server_socket, &end, 0);
1178 if (*end != '\0')
1179 fd = -1;
1180 } else {
1181 fd = -1;
1182 }
1183
1184 if (fd != -1) {
1185 primary_client = wl_client_create(display, fd);
1186 if (!primary_client) {
1187 weston_log("fatal: failed to add client: %m\n");
1188 goto out;
1189 }
1190 primary_client_destroyed.notify =
1191 handle_primary_client_destroyed;
1192 wl_client_add_destroy_listener(primary_client,
1193 &primary_client_destroyed);
1194 } else if (weston_create_listening_socket(display, socket_name)) {
1195 goto out;
1196 }
1197
1198 if (!shell)
1199 weston_config_section_get_string(section, "shell", &shell,
1200 "desktop-shell.so");
1201
1202 if (load_modules(ec, shell, &argc, argv) < 0)
1203 goto out;
1204
1205 weston_config_section_get_string(section, "modules", &modules, "");
1206 if (load_modules(ec, modules, &argc, argv) < 0)
1207 goto out;
1208
1209 if (load_modules(ec, option_modules, &argc, argv) < 0)
1210 goto out;
1211
1212 section = weston_config_get_section(config, "keyboard", NULL, NULL);
1213 weston_config_section_get_bool(section, "numlock-on", &numlock_on, 0);
1214 if (numlock_on) {
1215 wl_list_for_each(seat, &ec->seat_list, link) {
Derek Foreman1281a362015-07-31 16:55:32 -05001216 struct weston_keyboard *keyboard =
1217 weston_seat_get_keyboard(seat);
1218
1219 if (keyboard)
1220 weston_keyboard_set_locks(keyboard,
Giulio Camuffobab996e2014-10-12 00:24:25 +03001221 WESTON_NUM_LOCK,
1222 WESTON_NUM_LOCK);
1223 }
1224 }
1225
1226 for (i = 1; i < argc; i++)
1227 weston_log("fatal: unhandled option: %s\n", argv[i]);
1228 if (argc > 1)
1229 goto out;
1230
1231 weston_compositor_wake(ec);
1232
1233 wl_display_run(display);
1234
1235 /* Allow for setting return exit code after
1236 * wl_display_run returns normally. This is
1237 * useful for devs/testers and automated tests
1238 * that want to indicate failure status to
1239 * testing infrastructure above
1240 */
1241 ret = ec->exit_code;
1242
1243out:
1244 weston_compositor_destroy(ec);
1245
1246out_signals:
1247 for (i = ARRAY_LENGTH(signals) - 1; i >= 0; i--)
1248 if (signals[i])
1249 wl_event_source_remove(signals[i]);
1250
1251 wl_display_destroy(display);
1252
1253 weston_log_file_close();
1254
1255 if (config)
1256 weston_config_destroy(config);
1257 free(config_file);
1258 free(backend);
1259 free(shell);
1260 free(socket_name);
1261 free(option_modules);
1262 free(log);
1263 free(modules);
1264
1265 return ret;
1266}