summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShawn Landden <shawn@churchofgit.com>2015-03-10 21:01:47 -0700
committerAnthony G. Basile <blueness@gentoo.org>2015-03-18 21:01:30 -0400
commit3a864f5e04d496dd2515bfd932c83e700e326ba1 (patch)
treeca911b92de9cea2f278551229c7ee359285890eb /src
parent8c6168fcba36c81505a175c8339404bc4be21263 (diff)
udev-ctrl: fix strict aliasing issues
it is ironic that "The only purpose of this structure is to cast the structure pointer passed in addr in order to avoid compiler warnings. See EXAMPLE below." from bind(2) Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src')
-rw-r--r--src/udev/udev-ctrl.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c
index a4cc306491..136db091e0 100644
--- a/src/udev/udev-ctrl.c
+++ b/src/udev/udev-ctrl.c
@@ -21,6 +21,7 @@
#include <sys/socket.h>
#include <sys/un.h>
+#include "socket-util.h"
#include "udev.h"
/* wire protocol magic must match */
@@ -58,7 +59,7 @@ struct udev_ctrl {
int refcount;
struct udev *udev;
int sock;
- struct sockaddr_un saddr;
+ union sockaddr_union saddr;
socklen_t addrlen;
bool bound;
bool cleanup_socket;
@@ -97,9 +98,9 @@ struct udev_ctrl *udev_ctrl_new_from_fd(struct udev *udev, int fd) {
if (r < 0)
log_warning_errno(errno, "could not set SO_PASSCRED: %m");
- uctrl->saddr.sun_family = AF_LOCAL;
- strscpy(uctrl->saddr.sun_path, sizeof(uctrl->saddr.sun_path), "/run/udev/control");
- uctrl->addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(uctrl->saddr.sun_path);
+ uctrl->saddr.un.sun_family = AF_LOCAL;
+ strscpy(uctrl->saddr.un.sun_path, sizeof(uctrl->saddr.un.sun_path), "/run/udev/control");
+ uctrl->addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(uctrl->saddr.un.sun_path);
return uctrl;
}
@@ -111,10 +112,10 @@ int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl) {
int err;
if (!uctrl->bound) {
- err = bind(uctrl->sock, (struct sockaddr *)&uctrl->saddr, uctrl->addrlen);
+ err = bind(uctrl->sock, &uctrl->saddr.sa, uctrl->addrlen);
if (err < 0 && errno == EADDRINUSE) {
- unlink(uctrl->saddr.sun_path);
- err = bind(uctrl->sock, (struct sockaddr *)&uctrl->saddr, uctrl->addrlen);
+ unlink(uctrl->saddr.un.sun_path);
+ err = bind(uctrl->sock, &uctrl->saddr.sa, uctrl->addrlen);
}
if (err < 0) {
@@ -163,7 +164,7 @@ int udev_ctrl_cleanup(struct udev_ctrl *uctrl) {
if (uctrl == NULL)
return 0;
if (uctrl->cleanup_socket)
- unlink(uctrl->saddr.sun_path);
+ unlink(uctrl->saddr.un.sun_path);
return 0;
}
@@ -273,7 +274,7 @@ static int ctrl_send(struct udev_ctrl *uctrl, enum udev_ctrl_msg_type type, int
ctrl_msg_wire.intval = intval;
if (!uctrl->connected) {
- if (connect(uctrl->sock, (struct sockaddr *)&uctrl->saddr, uctrl->addrlen) < 0) {
+ if (connect(uctrl->sock, &uctrl->saddr.sa, uctrl->addrlen) < 0) {
err = -errno;
goto out;
}