weston-launcher: Fix aliasing warnings

Kristian Høgsberg 13 years ago
parent 035dd9c4de
commit 9e14091778
  1. 17
      src/launcher-util.c
  2. 19
      src/weston-launch.c

@ -37,16 +37,19 @@
#include "launcher-util.h" #include "launcher-util.h"
#include "weston-launch.h" #include "weston-launch.h"
union cmsg_data { unsigned char b[4]; int fd; };
int int
weston_launcher_open(struct weston_compositor *compositor, weston_launcher_open(struct weston_compositor *compositor,
const char *path, int flags) const char *path, int flags)
{ {
int sock = compositor->launcher_sock; int sock = compositor->launcher_sock;
int fd, n, ret = -1; int n, ret = -1;
struct msghdr msg; struct msghdr msg;
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
struct iovec iov; struct iovec iov;
char control[CMSG_SPACE(sizeof fd)]; union cmsg_data *data;
char control[CMSG_SPACE(sizeof data->fd)];
ssize_t len; ssize_t len;
struct weston_launcher_open *message; struct weston_launcher_open *message;
@ -90,15 +93,15 @@ weston_launcher_open(struct weston_compositor *compositor,
goto out; goto out;
} }
fd = *(int *) CMSG_DATA(cmsg); data = (union cmsg_data *) CMSG_DATA(cmsg);
if (fd == -1) { if (data->fd == -1) {
fprintf(stderr, "missing drm fd in socket request"); fprintf(stderr, "missing drm fd in socket request");
return -1; return -1;
} }
out: out:
free(message); free(message);
return ret < 0 ? ret : fd; return ret < 0 ? ret : data->fd;
} }
int int
@ -112,6 +115,7 @@ weston_launcher_drm_set_master(struct weston_compositor *compositor,
int ret; int ret;
ssize_t len; ssize_t len;
struct weston_launcher_set_master message; struct weston_launcher_set_master message;
union cmsg_data *data;
if (compositor->launcher_sock == -1) { if (compositor->launcher_sock == -1) {
if (master) if (master)
@ -130,7 +134,8 @@ weston_launcher_drm_set_master(struct weston_compositor *compositor,
cmsg->cmsg_type = SCM_RIGHTS; cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(drm_fd)); cmsg->cmsg_len = CMSG_LEN(sizeof(drm_fd));
*(int *) CMSG_DATA(cmsg) = drm_fd; data = (union cmsg_data *) CMSG_DATA(cmsg);
data->fd = drm_fd;
msg.msg_controllen = cmsg->cmsg_len; msg.msg_controllen = cmsg->cmsg_len;
iov.iov_base = &message; iov.iov_base = &message;

@ -75,6 +75,8 @@ struct weston_launch {
int verbose; int verbose;
}; };
union cmsg_data { unsigned char b[4]; int fd; };
static gid_t * static gid_t *
read_groups(void) read_groups(void)
{ {
@ -234,9 +236,10 @@ setenv_fd(const char *env, int fd)
static int static int
handle_setmaster(struct weston_launch *wl, struct msghdr *msg, ssize_t len) handle_setmaster(struct weston_launch *wl, struct msghdr *msg, ssize_t len)
{ {
int drm_fd = -1, ret = -1; int ret = -1;
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
struct weston_launcher_set_master *message; struct weston_launcher_set_master *message;
union cmsg_data *data;
if (len != sizeof(*message)) { if (len != sizeof(*message)) {
error(0, 0, "missing value in setmaster request"); error(0, 0, "missing value in setmaster request");
@ -253,18 +256,18 @@ handle_setmaster(struct weston_launch *wl, struct msghdr *msg, ssize_t len)
goto out; goto out;
} }
drm_fd = *(int *) CMSG_DATA(cmsg); data = (union cmsg_data *) CMSG_DATA(cmsg);
if (drm_fd == -1) { if (data->fd == -1) {
error(0, 0, "missing drm fd in socket request"); error(0, 0, "missing drm fd in socket request");
goto out; goto out;
} }
if (message->set_master) if (message->set_master)
ret = drmSetMaster(drm_fd); ret = drmSetMaster(data->fd);
else else
ret = drmDropMaster(drm_fd); ret = drmDropMaster(data->fd);
close(drm_fd); close(data->fd);
out: out:
do { do {
len = send(wl->sock[0], &ret, sizeof ret, 0); len = send(wl->sock[0], &ret, sizeof ret, 0);
@ -285,6 +288,7 @@ handle_open(struct weston_launch *wl, struct msghdr *msg, ssize_t len)
struct msghdr nmsg; struct msghdr nmsg;
struct iovec iov; struct iovec iov;
struct weston_launcher_open *message; struct weston_launcher_open *message;
union cmsg_data *data;
message = msg->msg_iov->iov_base; message = msg->msg_iov->iov_base;
if ((size_t)len < sizeof(*message)) if ((size_t)len < sizeof(*message))
@ -317,7 +321,8 @@ err0:
cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS; cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(fd)); cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
*(int *) CMSG_DATA(cmsg) = fd; data = (union cmsg_data *) CMSG_DATA(cmsg);
data->fd = fd;
nmsg.msg_controllen = cmsg->cmsg_len; nmsg.msg_controllen = cmsg->cmsg_len;
ret = 0; ret = 0;
} }

Loading…
Cancel
Save