3

我正在使用 inotify 来监视某些文件的更改。问题是 inotify_event event->name 是空的,所以我不知道哪个文件被修改了

为什么事件->名称为空?

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;
        }
4

1 回答 1

8

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.

于 2011-12-07T21:48:26.993 回答