#define _GNU_SOURCE 1 #include #include #include #include #include #include #include #include #include int main () { int file = creat ("foo", S_IRUSR | S_IWUSR); assert_perror (errno); close (file); int notifications = inotify_init (); assert_perror (errno); int watch = inotify_add_watch (notifications, "foo", IN_MODIFY | IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF); assert_perror (errno); if (fork () == 0) { unlink ("foo"); assert_perror (errno); exit (EXIT_SUCCESS); } struct inotify_event event; ssize_t count = read (notifications, &event, sizeof event); assert (count == sizeof event); assert (event.mask == IN_ATTRIB); struct stat st; stat ("foo", &st); if (errno != ENOENT) { printf ("funny, errno = %m, nlink = %li\n", st.st_nlink); abort (); } count = read (notifications, &event, sizeof event); assert (count == sizeof event); assert (event.mask == IN_DELETE_SELF); /* Bug #2: this returns EINVAL for no good reason. */ /* inotify_rm_watch (notifications, watch); */ /* assert_perror (errno); */ return EXIT_SUCCESS; }