Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011 Intel Corporation |
| 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and |
| 5 | * its documentation for any purpose is hereby granted without fee, provided |
| 6 | * that the above copyright notice appear in all copies and that both that |
| 7 | * copyright notice and this permission notice appear in supporting |
| 8 | * documentation, and that the name of the copyright holders not be used in |
| 9 | * advertising or publicity pertaining to distribution of the software |
| 10 | * without specific, written prior permission. The copyright holders make |
| 11 | * no representations about the suitability of this software for any |
| 12 | * purpose. It is provided "as is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 15 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 16 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 17 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 18 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 19 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 20 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 23 | #include "config.h" |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 24 | |
| 25 | #include <stdlib.h> |
| 26 | #include <stdio.h> |
| 27 | #include <string.h> |
| 28 | #include <sys/socket.h> |
| 29 | #include <sys/un.h> |
| 30 | #include <fcntl.h> |
| 31 | #include <errno.h> |
| 32 | #include <unistd.h> |
| 33 | #include <signal.h> |
| 34 | |
| 35 | #include "xwayland.h" |
| 36 | #include "xserver-server-protocol.h" |
| 37 | |
| 38 | |
| 39 | static int |
| 40 | weston_xserver_handle_event(int listen_fd, uint32_t mask, void *data) |
| 41 | { |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 42 | struct weston_xserver *wxs = data; |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 43 | char display[8], s[8]; |
| 44 | int sv[2], client_fd; |
| 45 | |
| 46 | if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 47 | weston_log("socketpair failed\n"); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 48 | return 1; |
| 49 | } |
| 50 | |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 51 | wxs->process.pid = fork(); |
| 52 | switch (wxs->process.pid) { |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 53 | case 0: |
| 54 | /* SOCK_CLOEXEC closes both ends, so we need to unset |
| 55 | * the flag on the client fd. */ |
| 56 | client_fd = dup(sv[1]); |
| 57 | if (client_fd < 0) |
| 58 | return 1; |
| 59 | |
| 60 | snprintf(s, sizeof s, "%d", client_fd); |
| 61 | setenv("WAYLAND_SOCKET", s, 1); |
| 62 | |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 63 | snprintf(display, sizeof display, ":%d", wxs->display); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 64 | |
| 65 | if (execl(XSERVER_PATH, |
| 66 | XSERVER_PATH, |
| 67 | display, |
| 68 | "-wayland", |
| 69 | "-rootless", |
| 70 | "-retro", |
| 71 | "-nolisten", "all", |
| 72 | "-terminate", |
| 73 | NULL) < 0) |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 74 | weston_log("exec failed: %m\n"); |
Kristian Høgsberg | a58290b | 2013-06-18 01:03:02 -0400 | [diff] [blame] | 75 | _exit(EXIT_FAILURE); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 76 | |
| 77 | default: |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 78 | weston_log("forked X server, pid %d\n", wxs->process.pid); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 79 | |
| 80 | close(sv[1]); |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 81 | wxs->client = wl_client_create(wxs->wl_display, sv[0]); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 82 | |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 83 | weston_watch_process(&wxs->process); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 84 | |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 85 | wl_event_source_remove(wxs->abstract_source); |
| 86 | wl_event_source_remove(wxs->unix_source); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 87 | break; |
| 88 | |
| 89 | case -1: |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 90 | weston_log( "failed to fork\n"); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 91 | break; |
| 92 | } |
| 93 | |
| 94 | return 1; |
| 95 | } |
| 96 | |
| 97 | static void |
| 98 | weston_xserver_shutdown(struct weston_xserver *wxs) |
| 99 | { |
| 100 | char path[256]; |
| 101 | |
| 102 | snprintf(path, sizeof path, "/tmp/.X%d-lock", wxs->display); |
| 103 | unlink(path); |
| 104 | snprintf(path, sizeof path, "/tmp/.X11-unix/X%d", wxs->display); |
| 105 | unlink(path); |
| 106 | if (wxs->process.pid == 0) { |
| 107 | wl_event_source_remove(wxs->abstract_source); |
| 108 | wl_event_source_remove(wxs->unix_source); |
| 109 | } |
| 110 | close(wxs->abstract_fd); |
| 111 | close(wxs->unix_fd); |
| 112 | if (wxs->wm) |
| 113 | weston_wm_destroy(wxs->wm); |
| 114 | wxs->loop = NULL; |
| 115 | } |
| 116 | |
| 117 | static void |
| 118 | weston_xserver_cleanup(struct weston_process *process, int status) |
| 119 | { |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 120 | struct weston_xserver *wxs = |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 121 | container_of(process, struct weston_xserver, process); |
| 122 | |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 123 | wxs->process.pid = 0; |
| 124 | wxs->client = NULL; |
| 125 | wxs->resource = NULL; |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 126 | |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 127 | wxs->abstract_source = |
| 128 | wl_event_loop_add_fd(wxs->loop, wxs->abstract_fd, |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 129 | WL_EVENT_READABLE, |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 130 | weston_xserver_handle_event, wxs); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 131 | |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 132 | wxs->unix_source = |
| 133 | wl_event_loop_add_fd(wxs->loop, wxs->unix_fd, |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 134 | WL_EVENT_READABLE, |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 135 | weston_xserver_handle_event, wxs); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 136 | |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 137 | if (wxs->wm) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 138 | weston_log("xserver exited, code %d\n", status); |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 139 | weston_wm_destroy(wxs->wm); |
| 140 | wxs->wm = NULL; |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 141 | } else { |
| 142 | /* If the X server crashes before it binds to the |
| 143 | * xserver interface, shut down and don't try |
| 144 | * again. */ |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 145 | weston_log("xserver crashing too fast: %d\n", status); |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 146 | weston_xserver_shutdown(wxs); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
| 150 | static void |
| 151 | bind_xserver(struct wl_client *client, |
| 152 | void *data, uint32_t version, uint32_t id) |
| 153 | { |
| 154 | struct weston_xserver *wxs = data; |
| 155 | |
| 156 | /* If it's a different client than the xserver we launched, |
| 157 | * don't start the wm. */ |
| 158 | if (client != wxs->client) |
| 159 | return; |
| 160 | |
| 161 | wxs->resource = |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame^] | 162 | wl_resource_create(client, &xserver_interface, |
| 163 | 1, id); |
| 164 | wl_resource_set_implementation(wxs->resource, &xserver_implementation, |
| 165 | wxs, NULL); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 166 | |
| 167 | wxs->wm = weston_wm_create(wxs); |
| 168 | if (wxs->wm == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 169 | weston_log("failed to create wm\n"); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | xserver_send_listen_socket(wxs->resource, wxs->abstract_fd); |
| 173 | xserver_send_listen_socket(wxs->resource, wxs->unix_fd); |
| 174 | } |
| 175 | |
| 176 | static int |
| 177 | bind_to_abstract_socket(int display) |
| 178 | { |
| 179 | struct sockaddr_un addr; |
| 180 | socklen_t size, name_size; |
| 181 | int fd; |
| 182 | |
| 183 | fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0); |
| 184 | if (fd < 0) |
| 185 | return -1; |
| 186 | |
| 187 | addr.sun_family = AF_LOCAL; |
| 188 | name_size = snprintf(addr.sun_path, sizeof addr.sun_path, |
| 189 | "%c/tmp/.X11-unix/X%d", 0, display); |
| 190 | size = offsetof(struct sockaddr_un, sun_path) + name_size; |
| 191 | if (bind(fd, (struct sockaddr *) &addr, size) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 192 | weston_log("failed to bind to @%s: %s\n", |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 193 | addr.sun_path + 1, strerror(errno)); |
| 194 | close(fd); |
| 195 | return -1; |
| 196 | } |
| 197 | |
| 198 | if (listen(fd, 1) < 0) { |
| 199 | close(fd); |
| 200 | return -1; |
| 201 | } |
| 202 | |
| 203 | return fd; |
| 204 | } |
| 205 | |
| 206 | static int |
| 207 | bind_to_unix_socket(int display) |
| 208 | { |
| 209 | struct sockaddr_un addr; |
| 210 | socklen_t size, name_size; |
| 211 | int fd; |
| 212 | |
| 213 | fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0); |
| 214 | if (fd < 0) |
| 215 | return -1; |
| 216 | |
| 217 | addr.sun_family = AF_LOCAL; |
| 218 | name_size = snprintf(addr.sun_path, sizeof addr.sun_path, |
| 219 | "/tmp/.X11-unix/X%d", display) + 1; |
| 220 | size = offsetof(struct sockaddr_un, sun_path) + name_size; |
| 221 | unlink(addr.sun_path); |
| 222 | if (bind(fd, (struct sockaddr *) &addr, size) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 223 | weston_log("failed to bind to %s (%s)\n", |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 224 | addr.sun_path, strerror(errno)); |
| 225 | close(fd); |
| 226 | return -1; |
| 227 | } |
| 228 | |
| 229 | if (listen(fd, 1) < 0) { |
| 230 | unlink(addr.sun_path); |
| 231 | close(fd); |
| 232 | return -1; |
| 233 | } |
| 234 | |
| 235 | return fd; |
| 236 | } |
| 237 | |
| 238 | static int |
| 239 | create_lockfile(int display, char *lockfile, size_t lsize) |
| 240 | { |
| 241 | char pid[16], *end; |
| 242 | int fd, size; |
| 243 | pid_t other; |
| 244 | |
| 245 | snprintf(lockfile, lsize, "/tmp/.X%d-lock", display); |
| 246 | fd = open(lockfile, O_WRONLY | O_CLOEXEC | O_CREAT | O_EXCL, 0444); |
| 247 | if (fd < 0 && errno == EEXIST) { |
| 248 | fd = open(lockfile, O_CLOEXEC, O_RDONLY); |
| 249 | if (fd < 0 || read(fd, pid, 11) != 11) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 250 | weston_log("can't read lock file %s: %s\n", |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 251 | lockfile, strerror(errno)); |
Rob Bradford | ef94085 | 2012-12-05 18:47:07 +0000 | [diff] [blame] | 252 | if (fd >= 0) |
| 253 | close (fd); |
| 254 | |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 255 | errno = EEXIST; |
| 256 | return -1; |
| 257 | } |
| 258 | |
| 259 | other = strtol(pid, &end, 0); |
| 260 | if (end != pid + 10) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 261 | weston_log("can't parse lock file %s\n", |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 262 | lockfile); |
| 263 | close(fd); |
| 264 | errno = EEXIST; |
| 265 | return -1; |
| 266 | } |
| 267 | |
| 268 | if (kill(other, 0) < 0 && errno == ESRCH) { |
| 269 | /* stale lock file; unlink and try again */ |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 270 | weston_log("unlinking stale lock file %s\n", lockfile); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 271 | close(fd); |
| 272 | if (unlink(lockfile)) |
| 273 | /* If we fail to unlink, return EEXIST |
| 274 | so we try the next display number.*/ |
| 275 | errno = EEXIST; |
| 276 | else |
| 277 | errno = EAGAIN; |
| 278 | return -1; |
| 279 | } |
| 280 | |
Martin Olsson | 1972141 | 2012-07-08 03:03:45 +0200 | [diff] [blame] | 281 | close(fd); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 282 | errno = EEXIST; |
| 283 | return -1; |
| 284 | } else if (fd < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 285 | weston_log("failed to create lock file %s: %s\n", |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 286 | lockfile, strerror(errno)); |
| 287 | return -1; |
| 288 | } |
| 289 | |
| 290 | /* Subtle detail: we use the pid of the wayland |
| 291 | * compositor, not the xserver in the lock file. */ |
| 292 | size = snprintf(pid, sizeof pid, "%10d\n", getpid()); |
| 293 | if (write(fd, pid, size) != size) { |
| 294 | unlink(lockfile); |
| 295 | close(fd); |
| 296 | return -1; |
| 297 | } |
| 298 | |
| 299 | close(fd); |
| 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | static void |
| 305 | weston_xserver_destroy(struct wl_listener *l, void *data) |
| 306 | { |
| 307 | struct weston_xserver *wxs = |
| 308 | container_of(l, struct weston_xserver, destroy_listener); |
| 309 | |
| 310 | if (!wxs) |
| 311 | return; |
| 312 | |
| 313 | if (wxs->loop) |
| 314 | weston_xserver_shutdown(wxs); |
| 315 | |
| 316 | free(wxs); |
| 317 | } |
| 318 | |
| 319 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 320 | module_init(struct weston_compositor *compositor, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 321 | int *argc, char *argv[]) |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 322 | |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 323 | { |
| 324 | struct wl_display *display = compositor->wl_display; |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 325 | struct weston_xserver *wxs; |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 326 | char lockfile[256], display_name[8]; |
| 327 | |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 328 | wxs = malloc(sizeof *wxs); |
| 329 | memset(wxs, 0, sizeof *wxs); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 330 | |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 331 | wxs->process.cleanup = weston_xserver_cleanup; |
| 332 | wxs->wl_display = display; |
| 333 | wxs->compositor = compositor; |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 334 | |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 335 | wxs->display = 0; |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 336 | |
| 337 | retry: |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 338 | if (create_lockfile(wxs->display, lockfile, sizeof lockfile) < 0) { |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 339 | if (errno == EAGAIN) { |
| 340 | goto retry; |
| 341 | } else if (errno == EEXIST) { |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 342 | wxs->display++; |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 343 | goto retry; |
| 344 | } else { |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 345 | free(wxs); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 346 | return -1; |
| 347 | } |
| 348 | } |
| 349 | |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 350 | wxs->abstract_fd = bind_to_abstract_socket(wxs->display); |
| 351 | if (wxs->abstract_fd < 0 && errno == EADDRINUSE) { |
| 352 | wxs->display++; |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 353 | unlink(lockfile); |
| 354 | goto retry; |
| 355 | } |
| 356 | |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 357 | wxs->unix_fd = bind_to_unix_socket(wxs->display); |
| 358 | if (wxs->unix_fd < 0) { |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 359 | unlink(lockfile); |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 360 | close(wxs->abstract_fd); |
| 361 | free(wxs); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 362 | return -1; |
| 363 | } |
| 364 | |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 365 | snprintf(display_name, sizeof display_name, ":%d", wxs->display); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 366 | weston_log("xserver listening on display %s\n", display_name); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 367 | setenv("DISPLAY", display_name, 1); |
| 368 | |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 369 | wxs->loop = wl_display_get_event_loop(display); |
| 370 | wxs->abstract_source = |
| 371 | wl_event_loop_add_fd(wxs->loop, wxs->abstract_fd, |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 372 | WL_EVENT_READABLE, |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 373 | weston_xserver_handle_event, wxs); |
| 374 | wxs->unix_source = |
| 375 | wl_event_loop_add_fd(wxs->loop, wxs->unix_fd, |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 376 | WL_EVENT_READABLE, |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 377 | weston_xserver_handle_event, wxs); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 378 | |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 379 | wl_display_add_global(display, &xserver_interface, wxs, bind_xserver); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 380 | |
Tiago Vignatti | f268446 | 2012-11-30 17:19:56 -0200 | [diff] [blame] | 381 | wxs->destroy_listener.notify = weston_xserver_destroy; |
| 382 | wl_signal_add(&compositor->destroy_signal, &wxs->destroy_listener); |
Kristian Høgsberg | e10b124 | 2012-05-21 16:48:05 -0400 | [diff] [blame] | 383 | |
| 384 | return 0; |
| 385 | } |