Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inotify inotify_event event->name is empty

Tags:

inotify

I am using inotify to monitor changes on some files. The problem is that inotify_event event->name is empty so I cant tell which file was modified

why is event->name empty?

fd = inotify_init();
wd = inotify_add_watch (m_fd, "/tmp/myfile", IN_MODIFY | IN_CREATE | IN_DELETE);
wd1 = inotify_add_watch (m_fd, "/tmp/myfile2", IN_MODIFY | IN_CREATE | IN_DELETE);
-----
unsigned char buffer[BUFFER_SIZE];

    ssize_t len = ACE_OS::read(fd, buffer, sizeof(buffer));
    ssize_t i = 0;

    while (i < len)
    {
        inotify_event *event = ( struct inotify_event * ) &buffer[ i ];
            i += EVENT_SIZE + event->len;
        }
like image 748
Shay Avatar asked Oct 30 '25 22:10

Shay


1 Answers

From the inotify man page...

The name field is only present when an event is returned for a file inside a watched directory; it identifies the file pathname relative to the watched directory. This pathname is null-terminated, and may include further null bytes to align subsequent reads to a suitable address boundary.

Since you're just watching files, and not directories, name will always be empty.

like image 116
Will Chappell Avatar answered Nov 01 '25 21:11

Will Chappell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!