mirror of https://github.com/mkerrisk/man-pages
fanotify.7: fanotify_read should use aligned buffer
Michael Kerrisk pointed me to alignment issues which may arise when reading misaligned integers. On some systems integer values can only be read if they are correctly aligned. Other system have a lower performance when reading from or writing to misaligned memory positions. Therefore, the buffer used to call read(2) for a fanotify file descriptor should have the same alignment as struct fanotify_event_metadata. Due to the casting to char* inside the macros FAN_EVENT_OK and FAN_EVENT_NEXT we can use any data structure for the buffer. With the patch an array of struct fanotify_event_metadata is used as buffer which seems a natural choice to ensure proper alignment. It should be remembered that the offset between events is given by field event_len and iterating over the array may not be allowable in future. Instead the macros should be used. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
parent
da9a495eaa
commit
864eccb901
|
@ -556,7 +556,7 @@ static void
|
|||
handle_events(int fd)
|
||||
{
|
||||
const struct fanotify_event_metadata *metadata;
|
||||
char buf[4096];
|
||||
struct fanotify_event_metadata buf[200];
|
||||
ssize_t len;
|
||||
char path[PATH_MAX];
|
||||
ssize_t path_len;
|
||||
|
@ -582,7 +582,7 @@ handle_events(int fd)
|
|||
|
||||
/* Point to the first event in the buffer */
|
||||
|
||||
metadata = (struct fanotify_event_metadata *) buf;
|
||||
metadata = buf;
|
||||
|
||||
/* Loop over all events in the buffer */
|
||||
|
||||
|
|
Loading…
Reference in New Issue