diff options
-rw-r--r-- | src/udev/udev-ctrl.c | 19 |
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; } |