|
1 | 1 | #include <stdio.h>
|
| 2 | +#include <stdlib.h> |
| 3 | +#include <string.h> |
| 4 | +#include <errno.h> |
2 | 5 | #include <sys/inotify.h>
|
3 | 6 |
|
| 7 | +#define INOTIFY_PATH "/tmp/" |
| 8 | + |
4 | 9 | int main(int argc, char *argv[])
|
5 | 10 | {
|
| 11 | + int ret; |
6 | 12 | int fd;
|
| 13 | + int wd; |
7 | 14 |
|
8 | 15 | fd = inotify_init();
|
| 16 | + if (fd < 0) { |
| 17 | + perror("inotify_init"); |
| 18 | + exit(EXIT_FAILURE); |
| 19 | + } |
| 20 | + |
| 21 | + wd = inotify_add_watch(fd, INOTIFY_PATH, IN_MODIFY | IN_CREATE | IN_DELETE); |
| 22 | + if (wd < 0) { |
| 23 | + fprintf(stderr, "Failed to add watch [%s] [%s]", INOTIFY_PATH, strerror(errno)); |
| 24 | + perror("inotify_add_watch"); |
| 25 | + exit(EXIT_FAILURE); |
| 26 | + } |
| 27 | + |
| 28 | + ret = inotify_rm_watch(fd, wd); |
| 29 | + if (ret < 0) { |
| 30 | + fprintf(stderr, "Failed to rm watch [fd : %d] [wd : %d] [%s]", fd, wd, strerror(errno)); |
| 31 | + perror("inotify_rm_watch"); |
| 32 | + exit(EXIT_FAILURE); |
| 33 | + } |
9 | 34 |
|
10 | 35 | return 0;
|
11 | 36 | }
|
0 commit comments