summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-12-10 01:45:43 +0100
committerLennart Poettering <lennart@poettering.net>2014-12-10 01:48:39 +0100
commitf7c1ad4fd4190bee32db0aa26c8e9fe7e19d8816 (patch)
tree5a0ea84fa0c4a33eb9ff43f16f09024e1c595ef7 /src/shared
parentdf63dda6d4b4fc90f895cfd40d54e15928671624 (diff)
core: unify how we iterate over inotify events
Let's add some syntactic sugar for iterating through inotify events, and use it everywhere.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c19
-rw-r--r--src/shared/util.h7
2 files changed, 11 insertions, 15 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 8c1cf52c0a..ff8835b72d 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -2100,9 +2100,9 @@ int acquire_terminal(
assert(notify >= 0);
for (;;) {
- uint8_t inotify_buffer[sizeof(struct inotify_event) + FILENAME_MAX];
- ssize_t l;
+ uint8_t buffer[INOTIFY_EVENT_MAX] _alignas_(struct inotify_event);
struct inotify_event *e;
+ ssize_t l;
if (timeout != USEC_INFINITY) {
usec_t n;
@@ -2123,9 +2123,8 @@ int acquire_terminal(
}
}
- l = read(notify, inotify_buffer, sizeof(inotify_buffer));
+ l = read(notify, buffer, sizeof(buffer));
if (l < 0) {
-
if (errno == EINTR || errno == EAGAIN)
continue;
@@ -2133,21 +2132,11 @@ int acquire_terminal(
goto fail;
}
- e = (struct inotify_event*) inotify_buffer;
-
- while (l > 0) {
- size_t step;
-
+ FOREACH_INOTIFY_EVENT(e, buffer, l) {
if (e->wd != wd || !(e->mask & IN_CLOSE)) {
r = -EIO;
goto fail;
}
-
- step = sizeof(struct inotify_event) + e->len;
- assert(step <= (size_t) l);
-
- e = (struct inotify_event*) ((uint8_t*) e + step);
- l -= step;
}
break;
diff --git a/src/shared/util.h b/src/shared/util.h
index b6fdf83302..61094cca2f 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -1031,3 +1031,10 @@ int unquote_many_words(const char **p, ...) _sentinel_;
int free_and_strdup(char **p, const char *s);
int sethostname_idempotent(const char *s);
+
+#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); \
+ (e) = (struct inotify_event*) ((uint8_t*) (e) + sizeof(struct inotify_event) + (e)->len))