blob: 99cb8681452372b073e6924a0a7c99e3108a4f2d [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.
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02005 * Copyright © 2010-2011 Benjamin Franzke
6 * Copyright © 2013 Jason Ekstrand
Giulio Camuffobab996e2014-10-12 00:24:25 +03007 *
8 * Permission is hereby granted, free of charge, to any person obtaining
9 * a copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial
18 * portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * SOFTWARE.
28 */
29
30#include "config.h"
31
32#include <unistd.h>
33#include <signal.h>
34#include <errno.h>
35#include <dlfcn.h>
Jussi Kukkonen649bbce2016-07-19 14:16:27 +030036#include <stdint.h>
Giulio Camuffobab996e2014-10-12 00:24:25 +030037#include <string.h>
38#include <sys/utsname.h>
39#include <sys/stat.h>
40#include <sys/wait.h>
Giulio Camuffofba27fb2016-06-02 21:48:10 +030041#include <sys/socket.h>
Giulio Camuffo8aedf7b2016-06-02 21:48:12 +030042#include <libinput.h>
Giulio Camuffobe2b11a2016-06-02 21:48:13 +030043#include <sys/time.h>
Giulio Camuffo179fcda2016-06-02 21:48:14 +030044#include <linux/limits.h>
Giulio Camuffobab996e2014-10-12 00:24:25 +030045
46#ifdef HAVE_LIBUNWIND
47#define UNW_LOCAL_ONLY
48#include <libunwind.h>
49#endif
50
Giulio Camuffo179fcda2016-06-02 21:48:14 +030051#include "weston.h"
Giulio Camuffobab996e2014-10-12 00:24:25 +030052#include "compositor.h"
53#include "../shared/os-compatibility.h"
54#include "../shared/helpers.h"
55#include "git-version.h"
56#include "version.h"
Giulio Camuffofba27fb2016-06-02 21:48:10 +030057#include "weston.h"
Giulio Camuffobab996e2014-10-12 00:24:25 +030058
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -070059#include "compositor-drm.h"
Benoit Gschwind3c530942016-04-15 20:28:32 -070060#include "compositor-headless.h"
Benoit Gschwindbd573102016-04-22 17:05:26 +020061#include "compositor-rdp.h"
Benoit Gschwind934e89a2016-04-27 23:56:42 +020062#include "compositor-fbdev.h"
Benoit Gschwinde16acab2016-04-15 20:28:31 -070063#include "compositor-x11.h"
Benoit Gschwind3ff10da2016-05-10 22:47:49 +020064#include "compositor-wayland.h"
65
66#define WINDOW_TITLE "Weston Compositor"
Benoit Gschwind3c530942016-04-15 20:28:32 -070067
Giulio Camuffobe2b11a2016-06-02 21:48:13 +030068static FILE *weston_logfile = NULL;
69
70static int cached_tm_mday = -1;
71
72static int weston_log_timestamp(void)
73{
74 struct timeval tv;
75 struct tm *brokendown_time;
76 char string[128];
77
78 gettimeofday(&tv, NULL);
79
80 brokendown_time = localtime(&tv.tv_sec);
81 if (brokendown_time == NULL)
82 return fprintf(weston_logfile, "[(NULL)localtime] ");
83
84 if (brokendown_time->tm_mday != cached_tm_mday) {
85 strftime(string, sizeof string, "%Y-%m-%d %Z", brokendown_time);
86 fprintf(weston_logfile, "Date: %s\n", string);
87
88 cached_tm_mday = brokendown_time->tm_mday;
89 }
90
91 strftime(string, sizeof string, "%H:%M:%S", brokendown_time);
92
93 return fprintf(weston_logfile, "[%s.%03li] ", string, tv.tv_usec/1000);
94}
95
96static void
97custom_handler(const char *fmt, va_list arg)
98{
99 weston_log_timestamp();
100 fprintf(weston_logfile, "libwayland: ");
101 vfprintf(weston_logfile, fmt, arg);
102}
103
104static void
105weston_log_file_open(const char *filename)
106{
107 wl_log_set_handler_server(custom_handler);
108
109 if (filename != NULL) {
110 weston_logfile = fopen(filename, "a");
111 if (weston_logfile)
112 os_fd_set_cloexec(fileno(weston_logfile));
113 }
114
115 if (weston_logfile == NULL)
116 weston_logfile = stderr;
117 else
118 setvbuf(weston_logfile, NULL, _IOLBF, 256);
119}
120
121static void
122weston_log_file_close(void)
123{
124 if ((weston_logfile != stderr) && (weston_logfile != NULL))
125 fclose(weston_logfile);
126 weston_logfile = stderr;
127}
128
129static int
130vlog(const char *fmt, va_list ap)
131{
132 int l;
133
134 l = weston_log_timestamp();
135 l += vfprintf(weston_logfile, fmt, ap);
136
137 return l;
138}
139
140static int
141vlog_continue(const char *fmt, va_list argp)
142{
143 return vfprintf(weston_logfile, fmt, argp);
144}
145
Giulio Camuffobab996e2014-10-12 00:24:25 +0300146static struct wl_list child_process_list;
147static struct weston_compositor *segv_compositor;
148
149static int
150sigchld_handler(int signal_number, void *data)
151{
152 struct weston_process *p;
153 int status;
154 pid_t pid;
155
156 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
157 wl_list_for_each(p, &child_process_list, link) {
158 if (p->pid == pid)
159 break;
160 }
161
162 if (&p->link == &child_process_list) {
163 weston_log("unknown child process exited\n");
164 continue;
165 }
166
167 wl_list_remove(&p->link);
168 p->cleanup(p, status);
169 }
170
171 if (pid < 0 && errno != ECHILD)
172 weston_log("waitpid error %m\n");
173
174 return 1;
175}
176
177#ifdef HAVE_LIBUNWIND
178
179static void
180print_backtrace(void)
181{
182 unw_cursor_t cursor;
183 unw_context_t context;
184 unw_word_t off;
185 unw_proc_info_t pip;
186 int ret, i = 0;
187 char procname[256];
188 const char *filename;
189 Dl_info dlinfo;
190
191 pip.unwind_info = NULL;
192 ret = unw_getcontext(&context);
193 if (ret) {
194 weston_log("unw_getcontext: %d\n", ret);
195 return;
196 }
197
198 ret = unw_init_local(&cursor, &context);
199 if (ret) {
200 weston_log("unw_init_local: %d\n", ret);
201 return;
202 }
203
204 ret = unw_step(&cursor);
205 while (ret > 0) {
206 ret = unw_get_proc_info(&cursor, &pip);
207 if (ret) {
208 weston_log("unw_get_proc_info: %d\n", ret);
209 break;
210 }
211
212 ret = unw_get_proc_name(&cursor, procname, 256, &off);
213 if (ret && ret != -UNW_ENOMEM) {
214 if (ret != -UNW_EUNSPEC)
215 weston_log("unw_get_proc_name: %d\n", ret);
216 procname[0] = '?';
217 procname[1] = 0;
218 }
219
220 if (dladdr((void *)(pip.start_ip + off), &dlinfo) && dlinfo.dli_fname &&
221 *dlinfo.dli_fname)
222 filename = dlinfo.dli_fname;
223 else
224 filename = "?";
225
226 weston_log("%u: %s (%s%s+0x%x) [%p]\n", i++, filename, procname,
227 ret == -UNW_ENOMEM ? "..." : "", (int)off, (void *)(pip.start_ip + off));
228
229 ret = unw_step(&cursor);
230 if (ret < 0)
231 weston_log("unw_step: %d\n", ret);
232 }
233}
234
235#else
236
237static void
238print_backtrace(void)
239{
240 void *buffer[32];
241 int i, count;
242 Dl_info info;
243
244 count = backtrace(buffer, ARRAY_LENGTH(buffer));
245 for (i = 0; i < count; i++) {
246 dladdr(buffer[i], &info);
247 weston_log(" [%016lx] %s (%s)\n",
248 (long) buffer[i],
249 info.dli_sname ? info.dli_sname : "--",
250 info.dli_fname);
251 }
252}
253
254#endif
255
Giulio Camuffofba27fb2016-06-02 21:48:10 +0300256static void
257child_client_exec(int sockfd, const char *path)
258{
259 int clientfd;
260 char s[32];
261 sigset_t allsigs;
262
263 /* do not give our signal mask to the new process */
264 sigfillset(&allsigs);
265 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
266
267 /* Launch clients as the user. Do not lauch clients with wrong euid.*/
268 if (seteuid(getuid()) == -1) {
269 weston_log("compositor: failed seteuid\n");
270 return;
271 }
272
273 /* SOCK_CLOEXEC closes both ends, so we dup the fd to get a
274 * non-CLOEXEC fd to pass through exec. */
275 clientfd = dup(sockfd);
276 if (clientfd == -1) {
277 weston_log("compositor: dup failed: %m\n");
278 return;
279 }
280
281 snprintf(s, sizeof s, "%d", clientfd);
282 setenv("WAYLAND_SOCKET", s, 1);
283
284 if (execl(path, path, NULL) < 0)
285 weston_log("compositor: executing '%s' failed: %m\n",
286 path);
287}
288
289WL_EXPORT struct wl_client *
290weston_client_launch(struct weston_compositor *compositor,
291 struct weston_process *proc,
292 const char *path,
293 weston_process_cleanup_func_t cleanup)
294{
295 int sv[2];
296 pid_t pid;
297 struct wl_client *client;
298
299 weston_log("launching '%s'\n", path);
300
301 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sv) < 0) {
302 weston_log("weston_client_launch: "
303 "socketpair failed while launching '%s': %m\n",
304 path);
305 return NULL;
306 }
307
308 pid = fork();
309 if (pid == -1) {
310 close(sv[0]);
311 close(sv[1]);
312 weston_log("weston_client_launch: "
313 "fork failed while launching '%s': %m\n", path);
314 return NULL;
315 }
316
317 if (pid == 0) {
318 child_client_exec(sv[1], path);
319 _exit(-1);
320 }
321
322 close(sv[1]);
323
324 client = wl_client_create(compositor->wl_display, sv[0]);
325 if (!client) {
326 close(sv[0]);
327 weston_log("weston_client_launch: "
328 "wl_client_create failed while launching '%s'.\n",
329 path);
330 return NULL;
331 }
332
333 proc->pid = pid;
334 proc->cleanup = cleanup;
335 weston_watch_process(proc);
336
337 return client;
338}
339
Giulio Camuffobab996e2014-10-12 00:24:25 +0300340WL_EXPORT void
341weston_watch_process(struct weston_process *process)
342{
343 wl_list_insert(&child_process_list, &process->link);
344}
345
Giulio Camuffofba27fb2016-06-02 21:48:10 +0300346struct process_info {
347 struct weston_process proc;
348 char *path;
349};
350
351static void
352process_handle_sigchld(struct weston_process *process, int status)
353{
354 struct process_info *pinfo =
355 container_of(process, struct process_info, proc);
356
357 /*
358 * There are no guarantees whether this runs before or after
359 * the wl_client destructor.
360 */
361
362 if (WIFEXITED(status)) {
363 weston_log("%s exited with status %d\n", pinfo->path,
364 WEXITSTATUS(status));
365 } else if (WIFSIGNALED(status)) {
366 weston_log("%s died on signal %d\n", pinfo->path,
367 WTERMSIG(status));
368 } else {
369 weston_log("%s disappeared\n", pinfo->path);
370 }
371
372 free(pinfo->path);
373 free(pinfo);
374}
375
376WL_EXPORT struct wl_client *
377weston_client_start(struct weston_compositor *compositor, const char *path)
378{
379 struct process_info *pinfo;
380 struct wl_client *client;
381
382 pinfo = zalloc(sizeof *pinfo);
383 if (!pinfo)
384 return NULL;
385
386 pinfo->path = strdup(path);
387 if (!pinfo->path)
388 goto out_free;
389
390 client = weston_client_launch(compositor, &pinfo->proc, path,
391 process_handle_sigchld);
392 if (!client)
393 goto out_str;
394
395 return client;
396
397out_str:
398 free(pinfo->path);
399
400out_free:
401 free(pinfo);
402
403 return NULL;
404}
405
Giulio Camuffobab996e2014-10-12 00:24:25 +0300406static void
407log_uname(void)
408{
409 struct utsname usys;
410
411 uname(&usys);
412
413 weston_log("OS: %s, %s, %s, %s\n", usys.sysname, usys.release,
414 usys.version, usys.machine);
415}
416
Giulio Camuffod52f3b72016-06-02 21:48:11 +0300417WL_EXPORT struct weston_config *
418wet_get_config(struct weston_compositor *compositor)
419{
420 return weston_compositor_get_user_data(compositor);
421}
422
Giulio Camuffobab996e2014-10-12 00:24:25 +0300423static const char xdg_error_message[] =
424 "fatal: environment variable XDG_RUNTIME_DIR is not set.\n";
425
426static const char xdg_wrong_message[] =
427 "fatal: environment variable XDG_RUNTIME_DIR\n"
428 "is set to \"%s\", which is not a directory.\n";
429
430static const char xdg_wrong_mode_message[] =
431 "warning: XDG_RUNTIME_DIR \"%s\" is not configured\n"
432 "correctly. Unix access mode must be 0700 (current mode is %o),\n"
433 "and must be owned by the user (current owner is UID %d).\n";
434
435static const char xdg_detail_message[] =
436 "Refer to your distribution on how to get it, or\n"
437 "http://www.freedesktop.org/wiki/Specifications/basedir-spec\n"
438 "on how to implement it.\n";
439
440static void
441verify_xdg_runtime_dir(void)
442{
443 char *dir = getenv("XDG_RUNTIME_DIR");
444 struct stat s;
445
446 if (!dir) {
447 weston_log(xdg_error_message);
448 weston_log_continue(xdg_detail_message);
449 exit(EXIT_FAILURE);
450 }
451
452 if (stat(dir, &s) || !S_ISDIR(s.st_mode)) {
453 weston_log(xdg_wrong_message, dir);
454 weston_log_continue(xdg_detail_message);
455 exit(EXIT_FAILURE);
456 }
457
458 if ((s.st_mode & 0777) != 0700 || s.st_uid != getuid()) {
459 weston_log(xdg_wrong_mode_message,
460 dir, s.st_mode & 0777, s.st_uid);
461 weston_log_continue(xdg_detail_message);
462 }
463}
464
465static int
466usage(int error_code)
467{
468 fprintf(stderr,
469 "Usage: weston [OPTIONS]\n\n"
470 "This is weston version " VERSION ", the Wayland reference compositor.\n"
471 "Weston supports multiple backends, and depending on which backend is in use\n"
472 "different options will be accepted.\n\n"
473
474
475 "Core options:\n\n"
476 " --version\t\tPrint weston version\n"
477 " -B, --backend=MODULE\tBackend module, one of\n"
478#if defined(BUILD_DRM_COMPOSITOR)
479 "\t\t\t\tdrm-backend.so\n"
480#endif
481#if defined(BUILD_FBDEV_COMPOSITOR)
482 "\t\t\t\tfbdev-backend.so\n"
483#endif
Dawid Gajownik71f57042015-07-31 17:39:00 -0300484#if defined(BUILD_HEADLESS_COMPOSITOR)
485 "\t\t\t\theadless-backend.so\n"
Giulio Camuffobab996e2014-10-12 00:24:25 +0300486#endif
487#if defined(BUILD_RDP_COMPOSITOR)
488 "\t\t\t\trdp-backend.so\n"
489#endif
Dawid Gajownik71f57042015-07-31 17:39:00 -0300490#if defined(BUILD_WAYLAND_COMPOSITOR)
491 "\t\t\t\twayland-backend.so\n"
492#endif
493#if defined(BUILD_X11_COMPOSITOR)
494 "\t\t\t\tx11-backend.so\n"
495#endif
Giulio Camuffobab996e2014-10-12 00:24:25 +0300496 " --shell=MODULE\tShell module, defaults to desktop-shell.so\n"
497 " -S, --socket=NAME\tName of socket to listen on\n"
498 " -i, --idle-time=SECS\tIdle time in seconds\n"
499 " --modules\t\tLoad the comma-separated list of modules\n"
500 " --log=FILE\t\tLog to the given file\n"
501 " -c, --config=FILE\tConfig file to load, defaults to weston.ini\n"
502 " --no-config\t\tDo not read weston.ini\n"
503 " -h, --help\t\tThis help message\n\n");
504
505#if defined(BUILD_DRM_COMPOSITOR)
506 fprintf(stderr,
507 "Options for drm-backend.so:\n\n"
508 " --connector=ID\tBring up only this connector\n"
509 " --seat=SEAT\t\tThe seat that weston should run on\n"
510 " --tty=TTY\t\tThe tty to use\n"
511 " --use-pixman\t\tUse the pixman (CPU) renderer\n"
512 " --current-mode\tPrefer current KMS mode over EDID preferred mode\n\n");
513#endif
514
515#if defined(BUILD_FBDEV_COMPOSITOR)
516 fprintf(stderr,
517 "Options for fbdev-backend.so:\n\n"
518 " --tty=TTY\t\tThe tty to use\n"
519 " --device=DEVICE\tThe framebuffer device to use\n"
Pekka Paalanene77f8ad2016-06-08 17:39:37 +0300520 "\n");
Giulio Camuffobab996e2014-10-12 00:24:25 +0300521#endif
522
Dawid Gajownik71f57042015-07-31 17:39:00 -0300523#if defined(BUILD_HEADLESS_COMPOSITOR)
Giulio Camuffobab996e2014-10-12 00:24:25 +0300524 fprintf(stderr,
Dawid Gajownik71f57042015-07-31 17:39:00 -0300525 "Options for headless-backend.so:\n\n"
526 " --width=WIDTH\t\tWidth of memory surface\n"
527 " --height=HEIGHT\tHeight of memory surface\n"
Giulio Camuffobab996e2014-10-12 00:24:25 +0300528 " --transform=TR\tThe output transformation, TR is one of:\n"
529 "\tnormal 90 180 270 flipped flipped-90 flipped-180 flipped-270\n"
Armin Krezovićd84deeb2016-06-23 11:59:29 +0200530 " --use-pixman\t\tUse the pixman (CPU) renderer (default: no rendering)\n"
531 " --no-outputs\t\tDo not create any virtual outputs\n"
532 "\n");
Giulio Camuffobab996e2014-10-12 00:24:25 +0300533#endif
534
535#if defined(BUILD_RDP_COMPOSITOR)
536 fprintf(stderr,
537 "Options for rdp-backend.so:\n\n"
538 " --width=WIDTH\t\tWidth of desktop\n"
539 " --height=HEIGHT\tHeight of desktop\n"
Dawid Gajownikd99a0502015-07-31 14:49:57 -0300540 " --env-socket\t\tUse socket defined in RDP_FD env variable as peer connection\n"
Giulio Camuffobab996e2014-10-12 00:24:25 +0300541 " --address=ADDR\tThe address to bind\n"
542 " --port=PORT\t\tThe port to listen on\n"
543 " --no-clients-resize\tThe RDP peers will be forced to the size of the desktop\n"
544 " --rdp4-key=FILE\tThe file containing the key for RDP4 encryption\n"
545 " --rdp-tls-cert=FILE\tThe file containing the certificate for TLS encryption\n"
546 " --rdp-tls-key=FILE\tThe file containing the private key for TLS encryption\n"
547 "\n");
548#endif
549
Dawid Gajownik71f57042015-07-31 17:39:00 -0300550#if defined(BUILD_WAYLAND_COMPOSITOR)
551 fprintf(stderr,
552 "Options for wayland-backend.so:\n\n"
553 " --width=WIDTH\t\tWidth of Wayland surface\n"
554 " --height=HEIGHT\tHeight of Wayland surface\n"
555 " --scale=SCALE\t\tScale factor of output\n"
556 " --fullscreen\t\tRun in fullscreen mode\n"
557 " --use-pixman\t\tUse the pixman (CPU) renderer\n"
558 " --output-count=COUNT\tCreate multiple outputs\n"
559 " --sprawl\t\tCreate one fullscreen output for every parent output\n"
560 " --display=DISPLAY\tWayland display to connect to\n\n");
561#endif
562
563#if defined(BUILD_X11_COMPOSITOR)
564 fprintf(stderr,
565 "Options for x11-backend.so:\n\n"
566 " --width=WIDTH\t\tWidth of X window\n"
567 " --height=HEIGHT\tHeight of X window\n"
568 " --scale=SCALE\t\tScale factor of output\n"
569 " --fullscreen\t\tRun in fullscreen mode\n"
570 " --use-pixman\t\tUse the pixman (CPU) renderer\n"
571 " --output-count=COUNT\tCreate multiple outputs\n"
572 " --no-input\t\tDont create input devices\n\n");
Giulio Camuffobab996e2014-10-12 00:24:25 +0300573#endif
574
575 exit(error_code);
576}
577
578static int on_term_signal(int signal_number, void *data)
579{
580 struct wl_display *display = data;
581
582 weston_log("caught signal %d\n", signal_number);
583 wl_display_terminate(display);
584
585 return 1;
586}
587
588static void
589on_caught_signal(int s, siginfo_t *siginfo, void *context)
590{
591 /* This signal handler will do a best-effort backtrace, and
592 * then call the backend restore function, which will switch
593 * back to the vt we launched from or ungrab X etc and then
594 * raise SIGTRAP. If we run weston under gdb from X or a
595 * different vt, and tell gdb "handle *s* nostop", this
596 * will allow weston to switch back to gdb on crash and then
597 * gdb will catch the crash with SIGTRAP.*/
598
599 weston_log("caught signal: %d\n", s);
600
601 print_backtrace();
602
603 segv_compositor->backend->restore(segv_compositor);
604
605 raise(SIGTRAP);
606}
607
608static void
609catch_signals(void)
610{
611 struct sigaction action;
612
613 action.sa_flags = SA_SIGINFO | SA_RESETHAND;
614 action.sa_sigaction = on_caught_signal;
615 sigemptyset(&action.sa_mask);
616 sigaction(SIGSEGV, &action, NULL);
617 sigaction(SIGABRT, &action, NULL);
618}
619
620static const char *
621clock_name(clockid_t clk_id)
622{
623 static const char *names[] = {
624 [CLOCK_REALTIME] = "CLOCK_REALTIME",
625 [CLOCK_MONOTONIC] = "CLOCK_MONOTONIC",
626 [CLOCK_MONOTONIC_RAW] = "CLOCK_MONOTONIC_RAW",
627 [CLOCK_REALTIME_COARSE] = "CLOCK_REALTIME_COARSE",
628 [CLOCK_MONOTONIC_COARSE] = "CLOCK_MONOTONIC_COARSE",
Derek Foreman32838c92015-06-29 13:20:34 -0500629#ifdef CLOCK_BOOTTIME
Giulio Camuffobab996e2014-10-12 00:24:25 +0300630 [CLOCK_BOOTTIME] = "CLOCK_BOOTTIME",
Derek Foreman32838c92015-06-29 13:20:34 -0500631#endif
Giulio Camuffobab996e2014-10-12 00:24:25 +0300632 };
633
634 if (clk_id < 0 || (unsigned)clk_id >= ARRAY_LENGTH(names))
635 return "unknown";
636
637 return names[clk_id];
638}
639
640static const struct {
641 uint32_t bit; /* enum weston_capability */
642 const char *desc;
643} capability_strings[] = {
644 { WESTON_CAP_ROTATION_ANY, "arbitrary surface rotation:" },
645 { WESTON_CAP_CAPTURE_YFLIP, "screen capture uses y-flip:" },
646};
647
648static void
649weston_compositor_log_capabilities(struct weston_compositor *compositor)
650{
651 unsigned i;
652 int yes;
Pekka Paalanenbe112d42016-04-18 15:53:38 +0300653 struct timespec res;
Giulio Camuffobab996e2014-10-12 00:24:25 +0300654
655 weston_log("Compositor capabilities:\n");
656 for (i = 0; i < ARRAY_LENGTH(capability_strings); i++) {
657 yes = compositor->capabilities & capability_strings[i].bit;
658 weston_log_continue(STAMP_SPACE "%s %s\n",
659 capability_strings[i].desc,
660 yes ? "yes" : "no");
661 }
662
663 weston_log_continue(STAMP_SPACE "presentation clock: %s, id %d\n",
664 clock_name(compositor->presentation_clock),
665 compositor->presentation_clock);
Pekka Paalanenbe112d42016-04-18 15:53:38 +0300666
667 if (clock_getres(compositor->presentation_clock, &res) == 0)
668 weston_log_continue(STAMP_SPACE
669 "presentation clock resolution: %d.%09ld s\n",
670 (int)res.tv_sec, res.tv_nsec);
671 else
672 weston_log_continue(STAMP_SPACE
673 "presentation clock resolution: N/A\n");
Giulio Camuffobab996e2014-10-12 00:24:25 +0300674}
675
676static void
677handle_primary_client_destroyed(struct wl_listener *listener, void *data)
678{
679 struct wl_client *client = data;
680
681 weston_log("Primary client died. Closing...\n");
682
683 wl_display_terminate(wl_client_get_display(client));
684}
685
686static int
687weston_create_listening_socket(struct wl_display *display, const char *socket_name)
688{
689 if (socket_name) {
690 if (wl_display_add_socket(display, socket_name)) {
691 weston_log("fatal: failed to add socket: %m\n");
692 return -1;
693 }
694 } else {
695 socket_name = wl_display_add_socket_auto(display);
696 if (!socket_name) {
697 weston_log("fatal: failed to add socket: %m\n");
698 return -1;
699 }
700 }
701
702 setenv("WAYLAND_DISPLAY", socket_name, 1);
703
704 return 0;
705}
706
Giulio Camuffo179fcda2016-06-02 21:48:14 +0300707WL_EXPORT void *
708wet_load_module(const char *name, const char *entrypoint)
709{
710 const char *builddir = getenv("WESTON_BUILD_DIR");
711 char path[PATH_MAX];
712 void *module, *init;
713
714 if (name == NULL)
715 return NULL;
716
717 if (name[0] != '/') {
718 if (builddir)
719 snprintf(path, sizeof path, "%s/.libs/%s", builddir, name);
720 else
721 snprintf(path, sizeof path, "%s/%s", MODULEDIR, name);
722 } else {
723 snprintf(path, sizeof path, "%s", name);
724 }
725
726 module = dlopen(path, RTLD_NOW | RTLD_NOLOAD);
727 if (module) {
728 weston_log("Module '%s' already loaded\n", path);
729 dlclose(module);
730 return NULL;
731 }
732
733 weston_log("Loading module '%s'\n", path);
734 module = dlopen(path, RTLD_NOW);
735 if (!module) {
736 weston_log("Failed to load module: %s\n", dlerror());
737 return NULL;
738 }
739
740 init = dlsym(module, entrypoint);
741 if (!init) {
742 weston_log("Failed to lookup init function: %s\n", dlerror());
743 dlclose(module);
744 return NULL;
745 }
746
747 return init;
748}
749
Giulio Camuffobab996e2014-10-12 00:24:25 +0300750static int
751load_modules(struct weston_compositor *ec, const char *modules,
752 int *argc, char *argv[])
753{
754 const char *p, *end;
755 char buffer[256];
756 int (*module_init)(struct weston_compositor *ec,
757 int *argc, char *argv[]);
758
759 if (modules == NULL)
760 return 0;
761
762 p = modules;
763 while (*p) {
764 end = strchrnul(p, ',');
765 snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
Giulio Camuffo9c764df2016-06-29 11:54:27 +0200766
767 if (strstr(buffer, "xwayland.so")) {
768 if (wet_load_xwayland(ec) < 0)
769 return -1;
770 } else {
771 module_init = wet_load_module(buffer, "module_init");
772 if (!module_init)
773 return -1;
774 if (module_init(ec, argc, argv) < 0)
775 return -1;
776 }
Giulio Camuffobab996e2014-10-12 00:24:25 +0300777 p = end;
778 while (*p == ',')
779 p++;
780
781 }
782
783 return 0;
784}
785
786static int
787weston_compositor_init_config(struct weston_compositor *ec,
788 struct weston_config *config)
789{
790 struct xkb_rule_names xkb_names;
791 struct weston_config_section *s;
792 int repaint_msec;
Bob Ham91880f12016-01-12 10:21:47 +0000793 int vt_switching;
Giulio Camuffobab996e2014-10-12 00:24:25 +0300794
795 s = weston_config_get_section(config, "keyboard", NULL, NULL);
796 weston_config_section_get_string(s, "keymap_rules",
797 (char **) &xkb_names.rules, NULL);
798 weston_config_section_get_string(s, "keymap_model",
799 (char **) &xkb_names.model, NULL);
800 weston_config_section_get_string(s, "keymap_layout",
801 (char **) &xkb_names.layout, NULL);
802 weston_config_section_get_string(s, "keymap_variant",
803 (char **) &xkb_names.variant, NULL);
804 weston_config_section_get_string(s, "keymap_options",
805 (char **) &xkb_names.options, NULL);
806
Giulio Camuffo0358af42016-06-02 21:48:08 +0300807 if (weston_compositor_set_xkb_rule_names(ec, &xkb_names) < 0)
Giulio Camuffobab996e2014-10-12 00:24:25 +0300808 return -1;
809
810 weston_config_section_get_int(s, "repeat-rate",
811 &ec->kb_repeat_rate, 40);
812 weston_config_section_get_int(s, "repeat-delay",
813 &ec->kb_repeat_delay, 400);
814
Bob Ham91880f12016-01-12 10:21:47 +0000815 weston_config_section_get_bool(s, "vt-switching",
816 &vt_switching, true);
817 ec->vt_switching = vt_switching;
818
Giulio Camuffobab996e2014-10-12 00:24:25 +0300819 s = weston_config_get_section(config, "core", NULL, NULL);
820 weston_config_section_get_int(s, "repaint-window", &repaint_msec,
821 ec->repaint_msec);
822 if (repaint_msec < -10 || repaint_msec > 1000) {
823 weston_log("Invalid repaint_window value in config: %d\n",
824 repaint_msec);
825 } else {
826 ec->repaint_msec = repaint_msec;
827 }
828 weston_log("Output repaint window is %d ms maximum.\n",
829 ec->repaint_msec);
830
831 return 0;
832}
833
834static char *
835weston_choose_default_backend(void)
836{
837 char *backend = NULL;
838
839 if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET"))
840 backend = strdup("wayland-backend.so");
841 else if (getenv("DISPLAY"))
842 backend = strdup("x11-backend.so");
843 else
844 backend = strdup(WESTON_NATIVE_BACKEND);
845
846 return backend;
847}
848
849static const struct { const char *name; uint32_t token; } transforms[] = {
850 { "normal", WL_OUTPUT_TRANSFORM_NORMAL },
851 { "90", WL_OUTPUT_TRANSFORM_90 },
852 { "180", WL_OUTPUT_TRANSFORM_180 },
853 { "270", WL_OUTPUT_TRANSFORM_270 },
854 { "flipped", WL_OUTPUT_TRANSFORM_FLIPPED },
855 { "flipped-90", WL_OUTPUT_TRANSFORM_FLIPPED_90 },
856 { "flipped-180", WL_OUTPUT_TRANSFORM_FLIPPED_180 },
857 { "flipped-270", WL_OUTPUT_TRANSFORM_FLIPPED_270 },
858};
859
860WL_EXPORT int
861weston_parse_transform(const char *transform, uint32_t *out)
862{
863 unsigned int i;
864
865 for (i = 0; i < ARRAY_LENGTH(transforms); i++)
866 if (strcmp(transforms[i].name, transform) == 0) {
867 *out = transforms[i].token;
868 return 0;
869 }
870
871 *out = WL_OUTPUT_TRANSFORM_NORMAL;
872 return -1;
873}
874
875WL_EXPORT const char *
876weston_transform_to_string(uint32_t output_transform)
877{
878 unsigned int i;
879
880 for (i = 0; i < ARRAY_LENGTH(transforms); i++)
881 if (transforms[i].token == output_transform)
882 return transforms[i].name;
883
884 return "<illegal value>";
885}
886
887static int
888load_configuration(struct weston_config **config, int32_t noconfig,
889 const char *config_file)
890{
891 const char *file = "weston.ini";
892 const char *full_path;
893
894 *config = NULL;
895
896 if (config_file)
897 file = config_file;
898
899 if (noconfig == 0)
900 *config = weston_config_parse(file);
901
902 if (*config) {
903 full_path = weston_config_get_full_path(*config);
904
905 weston_log("Using config file '%s'\n", full_path);
906 setenv(WESTON_CONFIG_FILE_ENV_VAR, full_path, 1);
907
908 return 0;
909 }
910
911 if (config_file && noconfig == 0) {
912 weston_log("fatal: error opening or reading config file"
913 " '%s'.\n", config_file);
914
915 return -1;
916 }
917
918 weston_log("Starting with no config file.\n");
919 setenv(WESTON_CONFIG_FILE_ENV_VAR, "", 1);
920
921 return 0;
922}
923
924static void
925handle_exit(struct weston_compositor *c)
926{
927 wl_display_terminate(c->wl_display);
928}
929
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -0700930static enum weston_drm_backend_output_mode
931drm_configure_output(struct weston_compositor *c,
932 bool use_current_mode,
933 const char *name,
934 struct weston_drm_backend_output_config *config)
935{
Giulio Camuffod52f3b72016-06-02 21:48:11 +0300936 struct weston_config *wc = wet_get_config(c);
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -0700937 struct weston_config_section *section;
938 char *s;
939 int scale;
940 enum weston_drm_backend_output_mode mode =
941 WESTON_DRM_BACKEND_OUTPUT_PREFERRED;
942
943 section = weston_config_get_section(wc, "output", "name", name);
944 weston_config_section_get_string(section, "mode", &s, "preferred");
945 if (strcmp(s, "off") == 0) {
946 free(s);
947 return WESTON_DRM_BACKEND_OUTPUT_OFF;
948 }
949
950 if (use_current_mode || strcmp(s, "current") == 0) {
951 mode = WESTON_DRM_BACKEND_OUTPUT_CURRENT;
952 } else if (strcmp(s, "preferred") != 0) {
953 config->modeline = s;
954 s = NULL;
955 }
956 free(s);
957
958 weston_config_section_get_int(section, "scale", &scale, 1);
959 config->base.scale = scale >= 1 ? scale : 1;
960 weston_config_section_get_string(section, "transform", &s, "normal");
961 if (weston_parse_transform(s, &config->base.transform) < 0)
962 weston_log("Invalid transform \"%s\" for output %s\n",
963 s, name);
964 free(s);
965
966 weston_config_section_get_string(section,
967 "gbm-format", &config->gbm_format, NULL);
968 weston_config_section_get_string(section, "seat", &config->seat, "");
969 return mode;
970}
971
Giulio Camuffo8aedf7b2016-06-02 21:48:12 +0300972static void
973configure_input_device(struct weston_compositor *compositor,
974 struct libinput_device *device)
975{
976 struct weston_config_section *s;
977 struct weston_config *config = wet_get_config(compositor);
978 int enable_tap;
979 int enable_tap_default;
980
981 s = weston_config_get_section(config,
982 "libinput", NULL, NULL);
983
984 if (libinput_device_config_tap_get_finger_count(device) > 0) {
985 enable_tap_default =
986 libinput_device_config_tap_get_default_enabled(
987 device);
988 weston_config_section_get_bool(s, "enable_tap",
989 &enable_tap,
990 enable_tap_default);
991 libinput_device_config_tap_set_enabled(device,
992 enable_tap);
993 }
994}
995
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -0700996static int
Pekka Paalanen321ede72016-06-03 15:28:40 +0300997load_drm_backend(struct weston_compositor *c,
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -0700998 int *argc, char **argv, struct weston_config *wc)
999{
1000 struct weston_drm_backend_config config = {{ 0, }};
1001 struct weston_config_section *section;
1002 int ret = 0;
1003
1004 const struct weston_option options[] = {
1005 { WESTON_OPTION_INTEGER, "connector", 0, &config.connector },
1006 { WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
1007 { WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
1008 { WESTON_OPTION_BOOLEAN, "current-mode", 0, &config.use_current_mode },
1009 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
1010 };
1011
1012 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1013
1014 section = weston_config_get_section(wc, "core", NULL, NULL);
1015 weston_config_section_get_string(section,
1016 "gbm-format", &config.gbm_format,
1017 NULL);
1018
1019 config.base.struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION;
1020 config.base.struct_size = sizeof(struct weston_drm_backend_config);
1021 config.configure_output = drm_configure_output;
Giulio Camuffo8aedf7b2016-06-02 21:48:12 +03001022 config.configure_device = configure_input_device;
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -07001023
Pekka Paalanen50dbf382016-06-03 15:23:46 +03001024 ret = weston_compositor_load_backend(c, WESTON_BACKEND_DRM,
1025 &config.base);
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -07001026
1027 free(config.gbm_format);
1028 free(config.seat_id);
1029
1030 return ret;
1031}
1032
Giulio Camuffo43008c72015-10-17 19:24:15 +03001033static int
Pekka Paalanen321ede72016-06-03 15:28:40 +03001034load_headless_backend(struct weston_compositor *c,
Benoit Gschwind3c530942016-04-15 20:28:32 -07001035 int *argc, char **argv, struct weston_config *wc)
1036{
1037 struct weston_headless_backend_config config = {{ 0, }};
1038 int ret = 0;
Benoit Gschwind2da6d0c2016-04-29 15:21:54 +02001039 char *transform = NULL;
Benoit Gschwind3c530942016-04-15 20:28:32 -07001040
1041 config.width = 1024;
1042 config.height = 640;
1043
1044 const struct weston_option options[] = {
1045 { WESTON_OPTION_INTEGER, "width", 0, &config.width },
1046 { WESTON_OPTION_INTEGER, "height", 0, &config.height },
1047 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
1048 { WESTON_OPTION_STRING, "transform", 0, &transform },
Armin Krezovićd84deeb2016-06-23 11:59:29 +02001049 { WESTON_OPTION_BOOLEAN, "no-outputs", 0, &config.no_outputs },
Benoit Gschwind3c530942016-04-15 20:28:32 -07001050 };
1051
1052 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1053
Benoit Gschwind2da6d0c2016-04-29 15:21:54 +02001054 config.transform = WL_OUTPUT_TRANSFORM_NORMAL;
1055 if (transform) {
1056 if (weston_parse_transform(transform, &config.transform) < 0)
1057 weston_log("Invalid transform \"%s\"\n", transform);
1058 free(transform);
1059 }
Benoit Gschwind3c530942016-04-15 20:28:32 -07001060
1061 config.base.struct_version = WESTON_HEADLESS_BACKEND_CONFIG_VERSION;
1062 config.base.struct_size = sizeof(struct weston_headless_backend_config);
1063
1064 /* load the actual wayland backend and configure it */
Pekka Paalanen50dbf382016-06-03 15:23:46 +03001065 ret = weston_compositor_load_backend(c, WESTON_BACKEND_HEADLESS,
1066 &config.base);
Benoit Gschwind3c530942016-04-15 20:28:32 -07001067
1068 return ret;
1069}
1070
Benoit Gschwindbd573102016-04-22 17:05:26 +02001071static void
1072weston_rdp_backend_config_init(struct weston_rdp_backend_config *config)
1073{
1074 config->base.struct_version = WESTON_RDP_BACKEND_CONFIG_VERSION;
1075 config->base.struct_size = sizeof(struct weston_rdp_backend_config);
1076
1077 config->width = 640;
1078 config->height = 480;
1079 config->bind_address = NULL;
1080 config->port = 3389;
1081 config->rdp_key = NULL;
1082 config->server_cert = NULL;
1083 config->server_key = NULL;
1084 config->env_socket = 0;
1085 config->no_clients_resize = 0;
1086}
1087
1088static int
Pekka Paalanen321ede72016-06-03 15:28:40 +03001089load_rdp_backend(struct weston_compositor *c,
Benoit Gschwindbd573102016-04-22 17:05:26 +02001090 int *argc, char *argv[], struct weston_config *wc)
1091{
1092 struct weston_rdp_backend_config config = {{ 0, }};
1093 int ret = 0;
1094
1095 weston_rdp_backend_config_init(&config);
1096
1097 const struct weston_option rdp_options[] = {
1098 { WESTON_OPTION_BOOLEAN, "env-socket", 0, &config.env_socket },
1099 { WESTON_OPTION_INTEGER, "width", 0, &config.width },
1100 { WESTON_OPTION_INTEGER, "height", 0, &config.height },
1101 { WESTON_OPTION_STRING, "address", 0, &config.bind_address },
1102 { WESTON_OPTION_INTEGER, "port", 0, &config.port },
1103 { WESTON_OPTION_BOOLEAN, "no-clients-resize", 0, &config.no_clients_resize },
1104 { WESTON_OPTION_STRING, "rdp4-key", 0, &config.rdp_key },
1105 { WESTON_OPTION_STRING, "rdp-tls-cert", 0, &config.server_cert },
1106 { WESTON_OPTION_STRING, "rdp-tls-key", 0, &config.server_key }
1107 };
1108
1109 parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv);
1110
Pekka Paalanen50dbf382016-06-03 15:23:46 +03001111 ret = weston_compositor_load_backend(c, WESTON_BACKEND_RDP,
1112 &config.base);
Benoit Gschwindbd573102016-04-22 17:05:26 +02001113
1114 free(config.bind_address);
1115 free(config.rdp_key);
1116 free(config.server_cert);
1117 free(config.server_key);
1118 return ret;
1119}
1120
Benoit Gschwind3c530942016-04-15 20:28:32 -07001121static int
Pekka Paalanen321ede72016-06-03 15:28:40 +03001122load_fbdev_backend(struct weston_compositor *c,
Benoit Gschwind934e89a2016-04-27 23:56:42 +02001123 int *argc, char **argv, struct weston_config *wc)
1124{
1125 struct weston_fbdev_backend_config config = {{ 0, }};
1126 struct weston_config_section *section;
1127 char *s = NULL;
1128 int ret = 0;
1129
1130 const struct weston_option fbdev_options[] = {
1131 { WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
1132 { WESTON_OPTION_STRING, "device", 0, &config.device },
Benoit Gschwind934e89a2016-04-27 23:56:42 +02001133 };
1134
1135 parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv);
1136
1137 if (!config.device)
1138 config.device = strdup("/dev/fb0");
1139
1140 section = weston_config_get_section(wc, "output", "name", "fbdev");
1141 weston_config_section_get_string(section, "transform", &s, "normal");
1142 if (weston_parse_transform(s, &config.output_transform) < 0)
1143 weston_log("Invalid transform \"%s\" for output fbdev\n", s);
1144 free(s);
1145
1146 config.base.struct_version = WESTON_FBDEV_BACKEND_CONFIG_VERSION;
1147 config.base.struct_size = sizeof(struct weston_fbdev_backend_config);
Giulio Camuffo8aedf7b2016-06-02 21:48:12 +03001148 config.configure_device = configure_input_device;
Benoit Gschwind934e89a2016-04-27 23:56:42 +02001149
1150 /* load the actual wayland backend and configure it */
Pekka Paalanen50dbf382016-06-03 15:23:46 +03001151 ret = weston_compositor_load_backend(c, WESTON_BACKEND_FBDEV,
1152 &config.base);
Benoit Gschwind934e89a2016-04-27 23:56:42 +02001153
1154 free(config.device);
Benoit Gschwinde16acab2016-04-15 20:28:31 -07001155
1156 return ret;
1157}
1158
1159static int
1160weston_x11_backend_config_append_output_config(struct weston_x11_backend_config *config,
1161 struct weston_x11_backend_output_config *output_config) {
1162 struct weston_x11_backend_output_config *new_outputs;
1163
1164 new_outputs = realloc(config->outputs, (config->num_outputs+1) *
1165 sizeof(struct weston_x11_backend_output_config));
1166 if (new_outputs == NULL)
1167 return -1;
1168
1169 config->outputs = new_outputs;
1170 config->outputs[config->num_outputs].width = output_config->width;
1171 config->outputs[config->num_outputs].height = output_config->height;
1172 config->outputs[config->num_outputs].transform = output_config->transform;
1173 config->outputs[config->num_outputs].scale = output_config->scale;
1174 config->outputs[config->num_outputs].name = strdup(output_config->name);
1175 config->num_outputs++;
1176
1177 return 0;
1178}
1179
1180static int
Pekka Paalanen321ede72016-06-03 15:28:40 +03001181load_x11_backend(struct weston_compositor *c,
Benoit Gschwinde16acab2016-04-15 20:28:31 -07001182 int *argc, char **argv, struct weston_config *wc)
1183{
1184 struct weston_x11_backend_output_config default_output;
1185 struct weston_x11_backend_config config = {{ 0, }};
1186 struct weston_config_section *section;
1187 int ret = 0;
1188 int option_width = 0;
1189 int option_height = 0;
1190 int option_scale = 0;
1191 int option_count = 1;
1192 int output_count = 0;
1193 char const *section_name;
1194 int i;
1195 uint32_t j;
1196
1197 const struct weston_option options[] = {
1198 { WESTON_OPTION_INTEGER, "width", 0, &option_width },
1199 { WESTON_OPTION_INTEGER, "height", 0, &option_height },
1200 { WESTON_OPTION_INTEGER, "scale", 0, &option_scale },
1201 { WESTON_OPTION_BOOLEAN, "fullscreen", 'f', &config.fullscreen },
1202 { WESTON_OPTION_INTEGER, "output-count", 0, &option_count },
1203 { WESTON_OPTION_BOOLEAN, "no-input", 0, &config.no_input },
1204 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
1205 };
1206
1207 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1208
1209 section = NULL;
1210 while (weston_config_next_section(wc, &section, &section_name)) {
1211 struct weston_x11_backend_output_config current_output = { 0, };
1212 char *t;
1213 char *mode;
1214
1215 if (strcmp(section_name, "output") != 0) {
1216 continue;
1217 }
1218
1219 weston_config_section_get_string(section, "name", &current_output.name, NULL);
1220 if (current_output.name == NULL || current_output.name[0] != 'X') {
1221 free(current_output.name);
1222 continue;
1223 }
1224
1225 weston_config_section_get_string(section, "mode", &mode, "1024x600");
1226 if (sscanf(mode, "%dx%d", &current_output.width,
1227 &current_output.height) != 2) {
1228 weston_log("Invalid mode \"%s\" for output %s\n",
1229 mode, current_output.name);
1230 current_output.width = 1024;
1231 current_output.height = 600;
1232 }
1233 free(mode);
1234 if (current_output.width < 1)
1235 current_output.width = 1024;
1236 if (current_output.height < 1)
1237 current_output.height = 600;
1238 if (option_width)
1239 current_output.width = option_width;
1240 if (option_height)
1241 current_output.height = option_height;
1242
1243 weston_config_section_get_int(section, "scale", &current_output.scale, 1);
1244 if (option_scale)
1245 current_output.scale = option_scale;
1246
1247 weston_config_section_get_string(section,
1248 "transform", &t, "normal");
1249 if (weston_parse_transform(t, &current_output.transform) < 0)
1250 weston_log("Invalid transform \"%s\" for output %s\n",
1251 t, current_output.name);
1252 free(t);
1253
1254 if (weston_x11_backend_config_append_output_config(&config, &current_output) < 0) {
1255 ret = -1;
1256 goto out;
1257 }
1258
1259 output_count++;
Bryce Harringtonaa258982016-05-03 01:34:23 -07001260 if (output_count >= option_count)
Benoit Gschwinde16acab2016-04-15 20:28:31 -07001261 break;
1262 }
1263
1264 default_output.name = NULL;
1265 default_output.width = option_width ? option_width : 1024;
1266 default_output.height = option_height ? option_height : 600;
1267 default_output.scale = option_scale ? option_scale : 1;
1268 default_output.transform = WL_OUTPUT_TRANSFORM_NORMAL;
1269
1270 for (i = output_count; i < option_count; i++) {
1271 if (asprintf(&default_output.name, "screen%d", i) < 0) {
1272 ret = -1;
1273 goto out;
1274 }
1275
1276 if (weston_x11_backend_config_append_output_config(&config, &default_output) < 0) {
1277 ret = -1;
1278 free(default_output.name);
1279 goto out;
1280 }
1281 free(default_output.name);
1282 }
1283
1284 config.base.struct_version = WESTON_X11_BACKEND_CONFIG_VERSION;
1285 config.base.struct_size = sizeof(struct weston_x11_backend_config);
1286
1287 /* load the actual backend and configure it */
Pekka Paalanen50dbf382016-06-03 15:23:46 +03001288 ret = weston_compositor_load_backend(c, WESTON_BACKEND_X11,
1289 &config.base);
Benoit Gschwinde16acab2016-04-15 20:28:31 -07001290
1291out:
1292 for (j = 0; j < config.num_outputs; ++j)
1293 free(config.outputs[j].name);
1294 free(config.outputs);
1295
Benoit Gschwind934e89a2016-04-27 23:56:42 +02001296 return ret;
1297}
1298
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001299static void
1300weston_wayland_output_config_init(struct weston_wayland_backend_output_config *output_config,
1301 struct weston_config_section *config_section,
1302 int option_width, int option_height,
1303 int option_scale)
1304{
1305 char *mode, *t, *str;
1306 unsigned int slen;
1307
1308 weston_config_section_get_string(config_section, "name", &output_config->name,
1309 NULL);
1310 if (output_config->name) {
1311 slen = strlen(output_config->name);
1312 slen += strlen(WINDOW_TITLE " - ");
1313 str = malloc(slen + 1);
1314 if (str)
1315 snprintf(str, slen + 1, WINDOW_TITLE " - %s",
1316 output_config->name);
1317 free(output_config->name);
1318 output_config->name = str;
1319 }
1320 if (!output_config->name)
1321 output_config->name = strdup(WINDOW_TITLE);
1322
1323 weston_config_section_get_string(config_section,
1324 "mode", &mode, "1024x600");
1325 if (sscanf(mode, "%dx%d", &output_config->width, &output_config->height) != 2) {
1326 weston_log("Invalid mode \"%s\" for output %s\n",
1327 mode, output_config->name);
1328 output_config->width = 1024;
1329 output_config->height = 640;
1330 }
1331 free(mode);
1332
1333 if (option_width)
1334 output_config->width = option_width;
1335 if (option_height)
1336 output_config->height = option_height;
1337
1338 weston_config_section_get_int(config_section, "scale", &output_config->scale, 1);
1339
1340 if (option_scale)
1341 output_config->scale = option_scale;
1342
1343 weston_config_section_get_string(config_section,
1344 "transform", &t, "normal");
1345 if (weston_parse_transform(t, &output_config->transform) < 0)
1346 weston_log("Invalid transform \"%s\" for output %s\n",
1347 t, output_config->name);
1348 free(t);
1349
1350}
1351
1352static void
Benoit Gschwinde48ab5f2016-05-10 22:47:55 +02001353weston_wayland_backend_config_release(struct weston_wayland_backend_config *config)
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001354{
1355 int i;
1356
Benoit Gschwinde48ab5f2016-05-10 22:47:55 +02001357 for (i = 0; i < config->num_outputs; ++i) {
1358 free(config->outputs[i].name);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001359 }
Benoit Gschwinde48ab5f2016-05-10 22:47:55 +02001360 free(config->cursor_theme);
1361 free(config->display_name);
1362 free(config->outputs);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001363}
1364
1365/*
1366 * Append a new output struct at the end of new_config.outputs and return a
1367 * pointer to the newly allocated structure or NULL if fail. The allocated
1368 * structure is NOT cleared nor set to default values.
1369 */
1370static struct weston_wayland_backend_output_config *
Benoit Gschwind44e302b2016-05-10 22:47:56 +02001371weston_wayland_backend_config_add_new_output(struct weston_wayland_backend_config *config)
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001372{
1373 struct weston_wayland_backend_output_config *outputs;
1374 const size_t element_size = sizeof(struct weston_wayland_backend_output_config);
1375
Benoit Gschwind44e302b2016-05-10 22:47:56 +02001376 outputs = realloc(config->outputs,
1377 (config->num_outputs + 1) * element_size);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001378 if (!outputs)
1379 return NULL;
Benoit Gschwind44e302b2016-05-10 22:47:56 +02001380 config->num_outputs += 1;
1381 config->outputs = outputs;
1382 return &(config->outputs[config->num_outputs - 1]);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001383}
1384
1385static int
1386load_wayland_backend_config(struct weston_compositor *compositor, int *argc,
Benoit Gschwind6c1cd2f2016-05-10 22:47:50 +02001387 char *argv[], struct weston_config *wc,
Benoit Gschwind55a22882016-05-10 22:47:51 +02001388 struct weston_wayland_backend_config *config)
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001389{
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001390 struct weston_config_section *section;
1391 struct weston_wayland_backend_output_config *oc;
1392 int count, width, height, scale;
1393 const char *section_name;
1394 char *name;
1395
1396 const struct weston_option wayland_options[] = {
1397 { WESTON_OPTION_INTEGER, "width", 0, &width },
1398 { WESTON_OPTION_INTEGER, "height", 0, &height },
1399 { WESTON_OPTION_INTEGER, "scale", 0, &scale },
Benoit Gschwind55a22882016-05-10 22:47:51 +02001400 { WESTON_OPTION_STRING, "display", 0, &config->display_name },
1401 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config->use_pixman },
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001402 { WESTON_OPTION_INTEGER, "output-count", 0, &count },
Benoit Gschwind55a22882016-05-10 22:47:51 +02001403 { WESTON_OPTION_BOOLEAN, "fullscreen", 0, &config->fullscreen },
1404 { WESTON_OPTION_BOOLEAN, "sprawl", 0, &config->sprawl },
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001405 };
1406
1407 width = 0;
1408 height = 0;
1409 scale = 0;
Benoit Gschwind55a22882016-05-10 22:47:51 +02001410 config->display_name = NULL;
1411 config->use_pixman = 0;
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001412 count = 1;
Benoit Gschwind55a22882016-05-10 22:47:51 +02001413 config->fullscreen = 0;
1414 config->sprawl = 0;
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001415 parse_options(wayland_options,
1416 ARRAY_LENGTH(wayland_options), argc, argv);
1417
Benoit Gschwind55a22882016-05-10 22:47:51 +02001418 config->cursor_size = 32;
1419 config->cursor_theme = NULL;
1420 config->base.struct_size = sizeof(struct weston_wayland_backend_config);
1421 config->base.struct_version = WESTON_WAYLAND_BACKEND_CONFIG_VERSION;
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001422
Benoit Gschwind6c1cd2f2016-05-10 22:47:50 +02001423 section = weston_config_get_section(wc, "shell", NULL, NULL);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001424 weston_config_section_get_string(section, "cursor-theme",
Benoit Gschwind55a22882016-05-10 22:47:51 +02001425 &config->cursor_theme, NULL);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001426 weston_config_section_get_int(section, "cursor-size",
Benoit Gschwind55a22882016-05-10 22:47:51 +02001427 &config->cursor_size, 32);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001428
Benoit Gschwind55a22882016-05-10 22:47:51 +02001429 if (config->sprawl) {
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001430 /* do nothing, everything is already set */
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001431 return 0;
1432 }
1433
Benoit Gschwind55a22882016-05-10 22:47:51 +02001434 if (config->fullscreen) {
Benoit Gschwind390af6d2016-05-10 22:47:52 +02001435 oc = weston_wayland_backend_config_add_new_output(config);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001436 if (!oc)
Benoit Gschwind53753842016-05-10 22:47:57 +02001437 return -1;
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001438
1439 oc->width = width;
1440 oc->height = height;
1441 oc->name = NULL;
1442 oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
1443 oc->scale = 1;
1444
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001445 return 0;
1446 }
1447
1448 section = NULL;
Benoit Gschwind6c1cd2f2016-05-10 22:47:50 +02001449 while (weston_config_next_section(wc, &section, &section_name)) {
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001450 if (!section_name || strcmp(section_name, "output") != 0)
1451 continue;
1452 weston_config_section_get_string(section, "name", &name, NULL);
1453 if (name == NULL)
1454 continue;
1455
1456 if (name[0] != 'W' || name[1] != 'L') {
1457 free(name);
1458 continue;
1459 }
1460 free(name);
1461
Benoit Gschwind390af6d2016-05-10 22:47:52 +02001462 oc = weston_wayland_backend_config_add_new_output(config);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001463 if (!oc)
Benoit Gschwind53753842016-05-10 22:47:57 +02001464 return -1;
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001465
1466 weston_wayland_output_config_init(oc, section, width,
1467 height, scale);
1468 --count;
1469 }
1470
1471 if (!width)
1472 width = 1024;
1473 if (!height)
1474 height = 640;
1475 if (!scale)
1476 scale = 1;
Benoit Gschwind55a22882016-05-10 22:47:51 +02001477
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001478 while (count > 0) {
Benoit Gschwind390af6d2016-05-10 22:47:52 +02001479 oc = weston_wayland_backend_config_add_new_output(config);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001480 if (!oc)
Benoit Gschwind53753842016-05-10 22:47:57 +02001481 return -1;
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001482
1483 oc->width = width;
1484 oc->height = height;
1485 oc->name = NULL;
1486 oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
1487 oc->scale = scale;
1488
1489 --count;
1490 }
1491
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001492 return 0;
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001493}
1494
1495static int
Pekka Paalanen321ede72016-06-03 15:28:40 +03001496load_wayland_backend(struct weston_compositor *c,
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001497 int *argc, char **argv, struct weston_config *wc)
1498{
1499 struct weston_wayland_backend_config config = {{ 0, }};
1500 int ret = 0;
1501
1502 ret = load_wayland_backend_config(c, argc, argv, wc, &config);
Bryce Harrington1dbdc0b2016-07-12 16:59:05 -07001503 if (ret < 0) {
Benoit Gschwind53753842016-05-10 22:47:57 +02001504 weston_wayland_backend_config_release(&config);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001505 return ret;
1506 }
1507
1508 /* load the actual wayland backend and configure it */
Pekka Paalanen50dbf382016-06-03 15:23:46 +03001509 ret = weston_compositor_load_backend(c, WESTON_BACKEND_WAYLAND,
1510 &config.base);
Benoit Gschwind68d6a6c2016-05-10 22:47:53 +02001511 weston_wayland_backend_config_release(&config);
Benoit Gschwind3ff10da2016-05-10 22:47:49 +02001512 return ret;
1513}
1514
1515
Benoit Gschwind934e89a2016-04-27 23:56:42 +02001516static int
Giulio Camuffo43008c72015-10-17 19:24:15 +03001517load_backend(struct weston_compositor *compositor, const char *backend,
1518 int *argc, char **argv, struct weston_config *config)
1519{
Benoit Gschwind3c530942016-04-15 20:28:32 -07001520 if (strstr(backend, "headless-backend.so"))
Pekka Paalanen321ede72016-06-03 15:28:40 +03001521 return load_headless_backend(compositor, argc, argv, config);
Benoit Gschwindbd573102016-04-22 17:05:26 +02001522 else if (strstr(backend, "rdp-backend.so"))
Pekka Paalanen321ede72016-06-03 15:28:40 +03001523 return load_rdp_backend(compositor, argc, argv, config);
Benoit Gschwind934e89a2016-04-27 23:56:42 +02001524 else if (strstr(backend, "fbdev-backend.so"))
Pekka Paalanen321ede72016-06-03 15:28:40 +03001525 return load_fbdev_backend(compositor, argc, argv, config);
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -07001526 else if (strstr(backend, "drm-backend.so"))
Pekka Paalanen321ede72016-06-03 15:28:40 +03001527 return load_drm_backend(compositor, argc, argv, config);
Benoit Gschwinde16acab2016-04-15 20:28:31 -07001528 else if (strstr(backend, "x11-backend.so"))
Pekka Paalanen321ede72016-06-03 15:28:40 +03001529 return load_x11_backend(compositor, argc, argv, config);
Giulio Camuffo43008c72015-10-17 19:24:15 +03001530 else if (strstr(backend, "wayland-backend.so"))
Pekka Paalanen321ede72016-06-03 15:28:40 +03001531 return load_wayland_backend(compositor, argc, argv, config);
Giulio Camuffo43008c72015-10-17 19:24:15 +03001532
Pekka Paalanen808b0062016-06-03 13:56:17 +03001533 weston_log("Error: unknown backend \"%s\"\n", backend);
1534 return -1;
Giulio Camuffo43008c72015-10-17 19:24:15 +03001535}
1536
Pekka Paalanen20436e22016-02-11 14:42:21 +02001537static char *
1538copy_command_line(int argc, char * const argv[])
1539{
1540 FILE *fp;
1541 char *str = NULL;
1542 size_t size = 0;
1543 int i;
1544
1545 fp = open_memstream(&str, &size);
1546 if (!fp)
1547 return NULL;
1548
1549 fprintf(fp, "%s", argv[0]);
1550 for (i = 1; i < argc; i++)
1551 fprintf(fp, " %s", argv[i]);
1552 fclose(fp);
1553
1554 return str;
1555}
1556
Giulio Camuffobab996e2014-10-12 00:24:25 +03001557int main(int argc, char *argv[])
1558{
1559 int ret = EXIT_FAILURE;
Pekka Paalanen20436e22016-02-11 14:42:21 +02001560 char *cmdline;
Giulio Camuffobab996e2014-10-12 00:24:25 +03001561 struct wl_display *display;
1562 struct weston_compositor *ec;
1563 struct wl_event_source *signals[4];
1564 struct wl_event_loop *loop;
Giulio Camuffobab996e2014-10-12 00:24:25 +03001565 int i, fd;
1566 char *backend = NULL;
1567 char *shell = NULL;
1568 char *modules = NULL;
1569 char *option_modules = NULL;
1570 char *log = NULL;
1571 char *server_socket = NULL, *end;
1572 int32_t idle_time = -1;
1573 int32_t help = 0;
1574 char *socket_name = NULL;
1575 int32_t version = 0;
1576 int32_t noconfig = 0;
1577 int32_t numlock_on;
1578 char *config_file = NULL;
1579 struct weston_config *config = NULL;
1580 struct weston_config_section *section;
1581 struct wl_client *primary_client;
1582 struct wl_listener primary_client_destroyed;
1583 struct weston_seat *seat;
1584
1585 const struct weston_option core_options[] = {
1586 { WESTON_OPTION_STRING, "backend", 'B', &backend },
1587 { WESTON_OPTION_STRING, "shell", 0, &shell },
1588 { WESTON_OPTION_STRING, "socket", 'S', &socket_name },
1589 { WESTON_OPTION_INTEGER, "idle-time", 'i', &idle_time },
1590 { WESTON_OPTION_STRING, "modules", 0, &option_modules },
1591 { WESTON_OPTION_STRING, "log", 0, &log },
1592 { WESTON_OPTION_BOOLEAN, "help", 'h', &help },
1593 { WESTON_OPTION_BOOLEAN, "version", 0, &version },
1594 { WESTON_OPTION_BOOLEAN, "no-config", 0, &noconfig },
1595 { WESTON_OPTION_STRING, "config", 'c', &config_file },
1596 };
1597
Pekka Paalanen20436e22016-02-11 14:42:21 +02001598 cmdline = copy_command_line(argc, argv);
Giulio Camuffobab996e2014-10-12 00:24:25 +03001599 parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv);
1600
Pekka Paalanen20436e22016-02-11 14:42:21 +02001601 if (help) {
1602 free(cmdline);
Giulio Camuffobab996e2014-10-12 00:24:25 +03001603 usage(EXIT_SUCCESS);
Pekka Paalanen20436e22016-02-11 14:42:21 +02001604 }
Giulio Camuffobab996e2014-10-12 00:24:25 +03001605
1606 if (version) {
1607 printf(PACKAGE_STRING "\n");
Pekka Paalanen20436e22016-02-11 14:42:21 +02001608 free(cmdline);
1609
Giulio Camuffobab996e2014-10-12 00:24:25 +03001610 return EXIT_SUCCESS;
1611 }
1612
Giulio Camuffobe2b11a2016-06-02 21:48:13 +03001613 weston_log_set_handler(vlog, vlog_continue);
Giulio Camuffobab996e2014-10-12 00:24:25 +03001614 weston_log_file_open(log);
1615
1616 weston_log("%s\n"
1617 STAMP_SPACE "%s\n"
1618 STAMP_SPACE "Bug reports to: %s\n"
1619 STAMP_SPACE "Build: %s\n",
1620 PACKAGE_STRING, PACKAGE_URL, PACKAGE_BUGREPORT,
1621 BUILD_ID);
Pekka Paalanen20436e22016-02-11 14:42:21 +02001622 weston_log("Command line: %s\n", cmdline);
1623 free(cmdline);
Giulio Camuffobab996e2014-10-12 00:24:25 +03001624 log_uname();
1625
1626 verify_xdg_runtime_dir();
1627
1628 display = wl_display_create();
1629
1630 loop = wl_display_get_event_loop(display);
1631 signals[0] = wl_event_loop_add_signal(loop, SIGTERM, on_term_signal,
1632 display);
1633 signals[1] = wl_event_loop_add_signal(loop, SIGINT, on_term_signal,
1634 display);
1635 signals[2] = wl_event_loop_add_signal(loop, SIGQUIT, on_term_signal,
1636 display);
1637
1638 wl_list_init(&child_process_list);
1639 signals[3] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler,
1640 NULL);
1641
1642 if (!signals[0] || !signals[1] || !signals[2] || !signals[3])
1643 goto out_signals;
1644
1645 if (load_configuration(&config, noconfig, config_file) < 0)
1646 goto out_signals;
1647
1648 section = weston_config_get_section(config, "core", NULL, NULL);
1649
1650 if (!backend) {
1651 weston_config_section_get_string(section, "backend", &backend,
1652 NULL);
1653 if (!backend)
1654 backend = weston_choose_default_backend();
1655 }
1656
Giulio Camuffo1c0e40d2016-04-29 15:40:34 -07001657 ec = weston_compositor_create(display, config);
Giulio Camuffobab996e2014-10-12 00:24:25 +03001658 if (ec == NULL) {
1659 weston_log("fatal: failed to create compositor\n");
Giulio Camuffo3c241b12015-10-03 16:25:16 +03001660 goto out;
Giulio Camuffobab996e2014-10-12 00:24:25 +03001661 }
1662
Giulio Camuffobab996e2014-10-12 00:24:25 +03001663 if (weston_compositor_init_config(ec, config) < 0)
Giulio Camuffo3c241b12015-10-03 16:25:16 +03001664 goto out;
Giulio Camuffobab996e2014-10-12 00:24:25 +03001665
Giulio Camuffo43008c72015-10-17 19:24:15 +03001666 if (load_backend(ec, backend, &argc, argv, config) < 0) {
Giulio Camuffobab996e2014-10-12 00:24:25 +03001667 weston_log("fatal: failed to create compositor backend\n");
Giulio Camuffo3c241b12015-10-03 16:25:16 +03001668 goto out;
Giulio Camuffobab996e2014-10-12 00:24:25 +03001669 }
1670
1671 catch_signals();
1672 segv_compositor = ec;
1673
1674 if (idle_time < 0)
1675 weston_config_section_get_int(section, "idle-time", &idle_time, -1);
1676 if (idle_time < 0)
1677 idle_time = 300; /* default idle timeout, in seconds */
1678
1679 ec->idle_time = idle_time;
1680 ec->default_pointer_grab = NULL;
1681 ec->exit = handle_exit;
1682
1683 weston_compositor_log_capabilities(ec);
1684
1685 server_socket = getenv("WAYLAND_SERVER_SOCKET");
1686 if (server_socket) {
1687 weston_log("Running with single client\n");
Bryce Harrington375759e2016-07-12 16:51:27 -07001688 fd = strtol(server_socket, &end, 10);
Giulio Camuffobab996e2014-10-12 00:24:25 +03001689 if (*end != '\0')
1690 fd = -1;
1691 } else {
1692 fd = -1;
1693 }
1694
1695 if (fd != -1) {
1696 primary_client = wl_client_create(display, fd);
1697 if (!primary_client) {
1698 weston_log("fatal: failed to add client: %m\n");
1699 goto out;
1700 }
1701 primary_client_destroyed.notify =
1702 handle_primary_client_destroyed;
1703 wl_client_add_destroy_listener(primary_client,
1704 &primary_client_destroyed);
1705 } else if (weston_create_listening_socket(display, socket_name)) {
1706 goto out;
1707 }
1708
1709 if (!shell)
1710 weston_config_section_get_string(section, "shell", &shell,
1711 "desktop-shell.so");
1712
1713 if (load_modules(ec, shell, &argc, argv) < 0)
1714 goto out;
1715
1716 weston_config_section_get_string(section, "modules", &modules, "");
1717 if (load_modules(ec, modules, &argc, argv) < 0)
1718 goto out;
1719
1720 if (load_modules(ec, option_modules, &argc, argv) < 0)
1721 goto out;
1722
1723 section = weston_config_get_section(config, "keyboard", NULL, NULL);
1724 weston_config_section_get_bool(section, "numlock-on", &numlock_on, 0);
1725 if (numlock_on) {
1726 wl_list_for_each(seat, &ec->seat_list, link) {
Derek Foreman1281a362015-07-31 16:55:32 -05001727 struct weston_keyboard *keyboard =
1728 weston_seat_get_keyboard(seat);
1729
1730 if (keyboard)
1731 weston_keyboard_set_locks(keyboard,
Giulio Camuffobab996e2014-10-12 00:24:25 +03001732 WESTON_NUM_LOCK,
1733 WESTON_NUM_LOCK);
1734 }
1735 }
1736
1737 for (i = 1; i < argc; i++)
1738 weston_log("fatal: unhandled option: %s\n", argv[i]);
1739 if (argc > 1)
1740 goto out;
1741
1742 weston_compositor_wake(ec);
1743
1744 wl_display_run(display);
1745
1746 /* Allow for setting return exit code after
1747 * wl_display_run returns normally. This is
1748 * useful for devs/testers and automated tests
1749 * that want to indicate failure status to
1750 * testing infrastructure above
1751 */
1752 ret = ec->exit_code;
1753
1754out:
1755 weston_compositor_destroy(ec);
1756
1757out_signals:
1758 for (i = ARRAY_LENGTH(signals) - 1; i >= 0; i--)
1759 if (signals[i])
1760 wl_event_source_remove(signals[i]);
1761
1762 wl_display_destroy(display);
1763
1764 weston_log_file_close();
1765
1766 if (config)
1767 weston_config_destroy(config);
1768 free(config_file);
1769 free(backend);
1770 free(shell);
1771 free(socket_name);
1772 free(option_modules);
1773 free(log);
1774 free(modules);
1775
1776 return ret;
1777}