Inotify event in C

Program:

#include <stdio.h>
#include <sys/inotify.h>

int main()
{
    int fd = inotify_init();
    int wd1 = inotify_add_watch(fd, "/home/guest/a", IN_MODIFY);
    struct inotify_event *event = (struct inotify_event*) malloc(sizeof(struct inotify_event));
    read(fd, event, 1000);
    if (event->mask & IN_MODIFY) {
        printf("File '%s' is modified\n", event->name);
    }
}

Output:

$ ./a.out 
File '' is modified
$

I expected the above program to report with the file name if file a is changed. But it is notified without a file name. So how to get the file name if the file was changed using inotify.

+4
source share
1 answer

The documentation says:

The name field is present only when the event is returned for the file inside the observed directory; it identifies the file path to the scanned directory. This path has zero completion and may include additional empty bytes ('\ 0') to align the subsequent matching address boundary.

, , , "" , , .

+4

Source: https://habr.com/ru/post/1621296/


All Articles