1 #include <sys/inotify.h> /* Linux inotify interface */
3 int main(int argc, char *argv[])
7 char buffer[512 * (sizeof(struct inotify_event) + 16)];
9 struct inotify_event * event;
12 if (narg < 1) { /* There must be at least one argument */
13 printf("Wrong number of arguments %d\n", argc - optind);
16 fd = inotify_init(); /* initialize inotify */
18 perror("Failing on inotify_init");
23 wd = inotify_add_watch(fd, argv[optind+i], mask); /* add watch */
25 printf("Failing to add watched file %s, mask %i; %s\n",
26 argv[optind+i], mask, strerror(errno));
31 /* Main Loop: read events and print them */
33 nread = read(fd, buffer, sizeof(buffer));
38 perror("error reading inotify data");
44 event = (struct inotify_event *) buffer + i;
45 printf("Watch descriptor %i\n", event->wd);
46 printf("Observed event on %s\n", argv[optind-1+event->wd]);
48 printf("On file %s\n", event->name);
50 printevent(event->mask);
51 i += sizeof(struct inotify_event) + event->len;