1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
4 #include "inotify-util.h"
7 bool inotify_event_next(
8 union inotify_event_buffer
*buffer
,
10 struct inotify_event
**iterator
,
13 struct inotify_event
*e
;
20 assert((uint8_t*) *iterator
>= buffer
->raw
);
21 offset
= (uint8_t*) *iterator
- buffer
->raw
;
22 offset
+= offsetof(struct inotify_event
, name
) + (*iterator
)->len
;
26 return false; /* reached end of list */
29 size
- offset
< offsetof(struct inotify_event
, name
)) {
30 log_full(log_level
, "Received invalid inotify event, ignoring.");
34 e
= CAST_ALIGN_PTR(struct inotify_event
, buffer
->raw
+ offset
);
35 if (size
- offset
- offsetof(struct inotify_event
, name
) < e
->len
) {
36 log_full(log_level
, "Received invalid inotify event, ignoring.");
44 int inotify_add_watch_fd(int fd
, int what
, uint32_t mask
) {
47 /* This is like inotify_add_watch(), except that the file to watch is not referenced by a path, but by an fd */
48 wd
= inotify_add_watch(fd
, FORMAT_PROC_FD_PATH(what
), mask
);
53 /* Didn't work with ENOENT? If so, then either /proc/ isn't mounted, or the fd is bad */
60 return -ENOENT
; /* OK, no clue, let's propagate the original error */
66 int inotify_add_watch_and_warn(int fd
, const char *pathname
, uint32_t mask
) {
69 wd
= inotify_add_watch(fd
, pathname
, mask
);
72 return log_error_errno(errno
, "Failed to add a watch for %s: inotify watch limit reached", pathname
);
74 return log_error_errno(errno
, "Failed to add a watch for %s: %m", pathname
);