inotify inotify_event 事件->名称为空

标签 inotify

我正在使用 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;
        }

最佳答案

来自 inotify 手册页...

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.

由于您只是查看文件,而不是目录,因此名称将始终为空。

关于inotify inotify_event 事件->名称为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7957132/

相关文章:

c - C中的Inotify事件

c++ - inotify_add_watch 失败,没有这样的文件或目录

linux - 在 FreeBSD 上监控大型目录的最有效方法是什么

c++ - 如何确保在完成写入之前不读取文件

linux - 如何打印导致 fswatch 执行某些操作的文件路径

创建文件时自动在服务器之间传输 Linux 文件

linux - Inotifywait 在一次执行后没有被执行

php - 更新 php 扩展 Ubuntu

c++ - Inotify 不适用于 etc/passwd

docker daemon 启动失败 : inotify_add_watch: no such file or directory