weston-launcher: Fix aliasing warnings

parent 035dd9c4
......@@ -37,16 +37,19 @@
#include "launcher-util.h"
#include "weston-launch.h"
union cmsg_data { unsigned char b[4]; int fd; };
int
weston_launcher_open(struct weston_compositor *compositor,
const char *path, int flags)
{
int sock = compositor->launcher_sock;
int fd, n, ret = -1;
int n, ret = -1;
struct msghdr msg;
struct cmsghdr *cmsg;
struct iovec iov;
char control[CMSG_SPACE(sizeof fd)];
union cmsg_data *data;
char control[CMSG_SPACE(sizeof data->fd)];
ssize_t len;
struct weston_launcher_open *message;
......@@ -90,15 +93,15 @@ weston_launcher_open(struct weston_compositor *compositor,
goto out;
}
fd = *(int *) CMSG_DATA(cmsg);
if (fd == -1) {
data = (union cmsg_data *) CMSG_DATA(cmsg);
if (data->fd == -1) {
fprintf(stderr, "missing drm fd in socket request");
return -1;
}
out:
free(message);
return ret < 0 ? ret : fd;
return ret < 0 ? ret : data->fd;
}
int
......@@ -112,6 +115,7 @@ weston_launcher_drm_set_master(struct weston_compositor *compositor,
int ret;
ssize_t len;
struct weston_launcher_set_master message;
union cmsg_data *data;
if (compositor->launcher_sock == -1) {
if (master)
......@@ -130,7 +134,8 @@ weston_launcher_drm_set_master(struct weston_compositor *compositor,
cmsg->cmsg_type = SCM_RIGHTS;
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;
iov.iov_base = &message;
......
......@@ -75,6 +75,8 @@ struct weston_launch {
int verbose;
};
union cmsg_data { unsigned char b[4]; int fd; };
static gid_t *
read_groups(void)
{
......@@ -234,9 +236,10 @@ setenv_fd(const char *env, int fd)
static int
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 weston_launcher_set_master *message;
union cmsg_data *data;
if (len != sizeof(*message)) {
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;
}
drm_fd = *(int *) CMSG_DATA(cmsg);
if (drm_fd == -1) {
data = (union cmsg_data *) CMSG_DATA(cmsg);
if (data->fd == -1) {
error(0, 0, "missing drm fd in socket request");
goto out;
}
if (message->set_master)
ret = drmSetMaster(drm_fd);
ret = drmSetMaster(data->fd);
else
ret = drmDropMaster(drm_fd);
ret = drmDropMaster(data->fd);
close(drm_fd);
close(data->fd);
out:
do {
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 iovec iov;
struct weston_launcher_open *message;
union cmsg_data *data;
message = msg->msg_iov->iov_base;
if ((size_t)len < sizeof(*message))
......@@ -317,7 +321,8 @@ err0:
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
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;
ret = 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment