diff options
Diffstat (limited to 'src/weston-launch.c')
-rw-r--r-- | src/weston-launch.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/src/weston-launch.c b/src/weston-launch.c index 31d9c65..4e0927f 100644 --- a/src/weston-launch.c +++ b/src/weston-launch.c @@ -236,14 +236,14 @@ handle_setmaster(struct weston_launch *wl, struct msghdr *msg, ssize_t len) { int drm_fd = -1, ret = -1; struct cmsghdr *cmsg; - char set_master; + struct weston_launcher_set_master *message; - if (len != 2) { + if (len != sizeof(*message)) { error(0, 0, "missing value in setmaster request"); goto out; } - set_master = ((char *)msg->msg_iov->iov_base)[1]; + message = msg->msg_iov->iov_base; cmsg = CMSG_FIRSTHDR(msg); if (!cmsg || @@ -259,7 +259,7 @@ handle_setmaster(struct weston_launch *wl, struct msghdr *msg, ssize_t len) goto out; } - if (set_master) + if (message->set_master) ret = drmSetMaster(drm_fd); else ret = drmDropMaster(drm_fd); @@ -278,28 +278,25 @@ out: static int handle_open(struct weston_launch *wl, struct msghdr *msg, ssize_t len) { - char *path; - int fd = -1, ret = -1, flags; + int fd = -1, ret = -1; char control[CMSG_SPACE(sizeof(fd))]; struct cmsghdr *cmsg; struct stat s; struct msghdr nmsg; struct iovec iov; - char *in; + struct weston_launcher_open *message; - in = msg->msg_iov->iov_base; - in[len-1] = '\0'; - - if (len < 6) + message = msg->msg_iov->iov_base; + if ((size_t)len < sizeof(*message)) goto err0; - flags = *((int *) (in+1)); - path = &in[5]; + /* Ensure path is null-terminated */ + ((char *) message)[len-1] = '\0'; - if (stat(path, &s) < 0) + if (stat(message->path, &s) < 0) goto err0; - fd = open(path, flags); + fd = open(message->path, message->flags); if (fd < 0) goto err0; @@ -329,7 +326,7 @@ err0: if (wl->verbose) fprintf(stderr, "weston-launch: opened %s: ret: %d, fd: %d\n", - path, ret, fd); + message->path, ret, fd); do { len = sendmsg(wl->sock[0], &nmsg, 0); } while (len < 0 && errno == EINTR); @@ -349,6 +346,7 @@ handle_socket_msg(struct weston_launch *wl) struct iovec iov; int ret = -1; ssize_t len; + struct weston_launcher_message *message; memset(&msg, 0, sizeof(msg)); iov.iov_base = buf; @@ -365,7 +363,8 @@ handle_socket_msg(struct weston_launch *wl) if (len < 1) return -1; - switch (buf[0]) { + message = (void *) buf; + switch (message->opcode) { case WESTON_LAUNCHER_OPEN: ret = handle_open(wl, &msg, len); break; |