diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-04-06 13:59:04 +0200 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-04-06 14:00:43 +0200 |
commit | 8c023d58570c4252ba28c6901faf0f5ed933ca59 (patch) | |
tree | 4b989a3e5e1472b644f690be28cc519666810d62 | |
parent | 11b27c4c1e7fd093b4f948292050da93f9fb50f2 (diff) |
weston-laucnh: Use int types for message opcodesweston-launch
Implemented using message structs.
-rw-r--r-- | src/launcher-util.c | 28 | ||||
-rw-r--r-- | src/weston-launch.c | 33 | ||||
-rw-r--r-- | src/weston-launch.h | 15 |
3 files changed, 45 insertions, 31 deletions
diff --git a/src/launcher-util.c b/src/launcher-util.c index 66af9dd..acfcc3e 100644 --- a/src/launcher-util.c +++ b/src/launcher-util.c @@ -47,23 +47,23 @@ weston_launcher_open(struct weston_compositor *compositor, struct cmsghdr *cmsg; struct iovec iov; char control[CMSG_SPACE(sizeof fd)]; - char *buf; ssize_t len; + struct weston_launcher_open *message; if (sock == -1) return open(path, flags); - n = 1 + sizeof(int) + strlen(path) + 1; - buf = malloc(n); - if (!buf) + n = sizeof(*message) + strlen(path) + 1; + message = malloc(n); + if (!message) return -1; - buf[0] = WESTON_LAUNCHER_OPEN; - *((int *) (buf+1)) = flags; - strcpy(&buf[5], path); + message->header.opcode = WESTON_LAUNCHER_OPEN; + message->flags = flags; + strcpy(message->path, path); do { - len = send(sock, buf, n, 0); + len = send(sock, message, n, 0); } while (len < 0 && errno == EINTR); memset(&msg, 0, sizeof msg); @@ -97,7 +97,7 @@ weston_launcher_open(struct weston_compositor *compositor, } out: - free(buf); + free(message); return ret < 0 ? ret : fd; } @@ -111,7 +111,7 @@ weston_launcher_drm_set_master(struct weston_compositor *compositor, char control[CMSG_SPACE(sizeof(drm_fd))]; int ret; ssize_t len; - char buf[2]; + struct weston_launcher_set_master message; if (compositor->launcher_sock == -1) { if (master) @@ -133,11 +133,11 @@ weston_launcher_drm_set_master(struct weston_compositor *compositor, *(int *) CMSG_DATA(cmsg) = drm_fd; msg.msg_controllen = cmsg->cmsg_len; - iov.iov_base = buf; - iov.iov_len = sizeof buf; + iov.iov_base = &message; + iov.iov_len = sizeof message; - buf[0] = WESTON_LAUNCHER_DRM_SET_MASTER; - buf[1] = master; + message.header.opcode = WESTON_LAUNCHER_DRM_SET_MASTER; + message.set_master = master; do { len = sendmsg(compositor->launcher_sock, &msg, 0); 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; diff --git a/src/weston-launch.h b/src/weston-launch.h index 9cc993a..5be013e 100644 --- a/src/weston-launch.h +++ b/src/weston-launch.h @@ -28,4 +28,19 @@ enum weston_launcher_opcode { WESTON_LAUNCHER_DRM_SET_MASTER }; +struct weston_launcher_message { + int opcode; +}; + +struct weston_launcher_open { + struct weston_launcher_message header; + int flags; + char path[0]; +}; + +struct weston_launcher_set_master { + struct weston_launcher_message header; + int set_master; +}; + #endif |