From 96ce74918fc9f535fc04d53e960862cdeb995222 Mon Sep 17 00:00:00 2001 From: Shawn Paul Landden Date: Mon, 29 Dec 2014 11:05:19 -0500 Subject: util: fix strict aliasing violations in use of struct inotify_event v5 There is alot of cleanup that will have to happen to turn on -fstrict-aliasing, but I think our code should be "correct" to the rule. Signed-off-by: Anthony G. Basile --- src/shared/util.c | 1 - src/shared/util.h | 10 ++++++++-- src/udev/udevd.c | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/shared/util.c b/src/shared/util.c index e58e51561b..6ef53b05ef 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include diff --git a/src/shared/util.h b/src/shared/util.h index 8cdb79cd8f..402203e0dd 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -31,6 +31,7 @@ #include #include #include +#include #include "time-util.h" #include "missing.h" @@ -463,6 +464,11 @@ int execute_command(const char *command, char *const argv[]); #define INOTIFY_EVENT_MAX (sizeof(struct inotify_event) + NAME_MAX + 1) #define FOREACH_INOTIFY_EVENT(e, buffer, sz) \ - for ((e) = (struct inotify_event*) (buffer); \ - (uint8_t*) (e) < (uint8_t*) (buffer) + (sz); \ + for ((e) = &buffer.ev; \ + (uint8_t*) (e) < (uint8_t*) (buffer.raw) + (sz); \ (e) = (struct inotify_event*) ((uint8_t*) (e) + sizeof(struct inotify_event) + (e)->len)) + +union inotify_event_buffer { + struct inotify_event ev; + uint8_t raw[INOTIFY_EVENT_MAX]; +}; diff --git a/src/udev/udevd.c b/src/udev/udevd.c index b519dc4c99..092fc95db3 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -807,11 +807,11 @@ static int synthesize_change(struct udev_device *dev) { } static int handle_inotify(struct udev *udev) { - uint8_t buffer[INOTIFY_EVENT_MAX] _alignas_(struct inotify_event); + union inotify_event_buffer buffer; struct inotify_event *e; ssize_t l; - l = read(fd_inotify, buffer, sizeof(buffer)); + l = read(fd_inotify, &buffer, sizeof(buffer)); if (l < 0) { if (errno == EAGAIN || errno == EINTR) return 0; -- cgit v1.2.3-54-g00ecf