2 * Copyright © 2012 Benjamin Franzke
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.
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.
28 #include <sys/socket.h>
29 #include <sys/types.h>
36 #include "compositor.h"
37 #include "launcher-util.h"
38 #include "weston-launch.h"
40 union cmsg_data { unsigned char b[4]; int fd; };
43 weston_launcher_open(struct weston_compositor *compositor,
44 const char *path, int flags)
46 int sock = compositor->launcher_sock;
51 union cmsg_data *data;
52 char control[CMSG_SPACE(sizeof data->fd)];
54 struct weston_launcher_open *message;
57 return open(path, flags | O_CLOEXEC);
59 n = sizeof(*message) + strlen(path) + 1;
64 message->header.opcode = WESTON_LAUNCHER_OPEN;
65 message->flags = flags;
66 strcpy(message->path, path);
69 len = send(sock, message, n, 0);
70 } while (len < 0 && errno == EINTR);
73 memset(&msg, 0, sizeof msg);
75 iov.iov_len = sizeof ret;
78 msg.msg_control = control;
79 msg.msg_controllen = sizeof control;
82 len = recvmsg(sock, &msg, MSG_CMSG_CLOEXEC);
83 } while (len < 0 && errno == EINTR);
85 if (len != sizeof ret ||
89 cmsg = CMSG_FIRSTHDR(&msg);
91 cmsg->cmsg_level != SOL_SOCKET ||
92 cmsg->cmsg_type != SCM_RIGHTS) {
93 fprintf(stderr, "invalid control message\n");
97 data = (union cmsg_data *) CMSG_DATA(cmsg);
99 fprintf(stderr, "missing drm fd in socket request\n");
107 weston_launcher_drm_set_master(struct weston_compositor *compositor,
108 int drm_fd, char master)
111 struct cmsghdr *cmsg;
113 char control[CMSG_SPACE(sizeof(drm_fd))];
116 struct weston_launcher_set_master message;
117 union cmsg_data *data;
119 if (compositor->launcher_sock == -1) {
121 return drmSetMaster(drm_fd);
123 return drmDropMaster(drm_fd);
126 memset(&msg, 0, sizeof msg);
129 msg.msg_control = control;
130 msg.msg_controllen = sizeof control;
131 cmsg = CMSG_FIRSTHDR(&msg);
132 cmsg->cmsg_level = SOL_SOCKET;
133 cmsg->cmsg_type = SCM_RIGHTS;
134 cmsg->cmsg_len = CMSG_LEN(sizeof(drm_fd));
136 data = (union cmsg_data *) CMSG_DATA(cmsg);
138 msg.msg_controllen = cmsg->cmsg_len;
140 iov.iov_base = &message;
141 iov.iov_len = sizeof message;
143 message.header.opcode = WESTON_LAUNCHER_DRM_SET_MASTER;
144 message.set_master = master;
147 len = sendmsg(compositor->launcher_sock, &msg, 0);
148 } while (len < 0 && errno == EINTR);
153 len = recv(compositor->launcher_sock, &ret, sizeof ret, 0);
154 } while (len < 0 && errno == EINTR);