这几乎与手册页中的示例相同。所有内容都会更新到最新版本。gcc是4.9.2岁。gdb是7.8.1。linux内核为3.17.6-1 (64位)。安装是最近的一次arch引导。以下是精简后的案例:
#define _GNU_SOURCE /* Needed to get O_LARGEFILE definition */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <sys/fanotify.h>
int main(int argc, char *argv[]) {
int fd;
fd = fanotify_init(FAN_CLOEXEC | FAN_CLASS_CONTENT | FAN_NONBLOCK, O_RDONLY | O_LARGEFILE);
if (fd == -1) exit(1);
fprintf(stderr, "calling fanotify_mark: fd=%d\n", fd);
if (fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_MOUNT, FAN_OPEN_PERM | FAN_CLOSE_WRITE, -1, "/") == -1) exit(2);
fprintf(stderr, "in gdb step through with 'n' for repeat.\n");
fprintf(stderr, " (and sometimes otherwise), a ^C works, but a ^Z and then ^C does not.\n");
}大多数情况下,这可以很好地工作,但有时并非如此。我想这就是fanotify_mark永远不会回来的时候。在尝试调试时,我发现我可以(不)复制它进行调试。如果我使用gdb并尝试使用'n‘单步执行,fanotify_mark()永远不会返回,并且是不可中断的(^C,^Z)。
这是否可以复制到其他地方,或者我做错了什么?
/iaw
发布于 2015-01-04 06:16:01
这是因为FAN_OPEN_PERM需要另一个程序来授予权限。这几乎与fanotify手册页中的示例完全相同-这使得它非常不幸,因为缩减程序可能会导致硬OS块。所以看着点。
我的实际意图是监视文件访问。为此,我们使用FAN_OPEN,而不是FAN_OPEN_PERM。
https://stackoverflow.com/questions/27645057
复制相似问题