1 2 3 4 5 6 7 8 9 10 11 12 | FD_ZERO(&rfds); FD_SET(fan_fd, &rfds); select(fan_fd+1, &rfds, NULL, NULL, NULL); while ((len = read(fan_fd, buf, sizeof(buf))) > 0) { 。。。 while(FAN_EVENT_OK(metadata, len)) { // 处理 metadata . . . metadata = FAN_EVENT_NEXT(metadata, len); // 读取下一个 metadata } select(fan_fd+1, &rfds, NULL, NULL, NULL) } |
1 2 3 4 5 6 7 8 9 | struct fanotify_event_metadata { __u32 event_len; __u8 vers; __u8 reserved; __u16 metadata_len; __aligned_u64 mask; __s32 fd; __s32 pid; }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | if (metadata->mask & FAN_ACCESS) printf(" access"); if (metadata->mask & FAN_OPEN) printf(" open"); if (metadata->mask & FAN_MODIFY) printf(" modify"); if (metadata->mask & FAN_CLOSE) { if (metadata->mask & FAN_CLOSE_WRITE) printf(" close(writable)"); if (metadata->mask & FAN_CLOSE_NOWRITE) printf(" close"); } if (metadata->mask & FAN_OPEN_PERM) printf(" open_perm"); if (metadata->mask & FAN_ACCESS_PERM) printf(" access_perm"); if (metadata->mask & FAN_ALL_PERM_EVENTS) { if (opt_sleep) sleep(opt_sleep); if (handle_perm(fan_fd, metadata)) goto fail; if (metadata->fd >= 0 && opt_ignore_perm && set_ignored_mask(fan_fd, metadata->fd, metadata->mask)) goto fail; } |
1 2 3 4 | struct fanotify_response { __s32 fd; __u32 response; }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | int handle_perm(int fan_fd, struct fanotify_event_metadata *metadata) { struct fanotify_response response_struct; int ret; response_struct.fd = metadata->fd; response_struct.response = FAN_ALLOW; ret = write(fan_fd, &response_struct, sizeof(response_struct)); if (ret < 0) return ret; return 0; } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |