-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathexample.c
69 lines (58 loc) · 1.53 KB
/
example.c
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fluffy.h>
int
main(int argc, char *argv[])
{
int ret = 0;
int flhandle = 0; /* Fluffy handle */
int rc = EXIT_SUCCESS; /* Return code */
if (argc < 2) {
fprintf(stderr, "Atleast a path required.\n");
exit(EXIT_FAILURE);
}
/* /proc/sys/fs/inotify/max_user_watches */
ret = fluffy_set_max_user_watches("524288");
if (ret != 0) {
fprintf(stderr, "fluffy_set_max_user_watches fail\n");
}
/* /proc/sys/fs/inotify/max_queued_events */
ret = fluffy_set_max_queued_events("524288");
if (ret != 0) {
fprintf(stderr, "fluffy_set_max_queued_events fail\n");
}
/*
* Initiate fluffy and print events on the standard out with the help
* of libfluffy's print event helper function.
*
* Look at fluffy.h for help with plugfing your custom event handler
*/
flhandle = fluffy_init(fluffy_print_event, (void *)&flhandle);
if (flhandle < 1) {
fprintf(stderr, "fluffy_init fail\n");
exit(EXIT_FAILURE);
}
do {
/* Watch argv[1] */
ret = fluffy_add_watch_path(flhandle, argv[1]);
if (ret != 0) {
fprintf(stderr, "fluffy_add_watch_path %s fail\n",
argv[1]);
rc = EXIT_FAILURE;
break;
}
/* Let us not exit until Fluffy exits/returns */
ret = fluffy_wait_until_done(flhandle);
if (ret != 0) {
fprintf(stderr, "fluffy_wait_until_done fail\n");
rc = EXIT_FAILURE;
break;
}
} while(0);
if (rc != EXIT_SUCCESS) {
ret = fluffy_destroy(flhandle); /* Destroy Fluffy context */
}
exit(rc);
}