-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinotify.c
More file actions
50 lines (37 loc) · 1.11 KB
/
inotify.c
File metadata and controls
50 lines (37 loc) · 1.11 KB
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
#include <sys/inotify.h>
#include <unistd.h>
#include "inotify.h"
#include "crl.h"
#include "log.h"
void inotify_cb(struct bufferevent *bev, void *arg) {
log_printf(LOG_DEBUG, "Read from crl_cache.txt\n");
//read from "crl_cache.txt", "crl_cache_info.txt"
}
//TODO: what to return??
inotify_ctx* set_inotify(struct event_base* ev_base) {
int fd; //,wd;
char buf[BUF_LEN] __attribute__ ((aligned(8)));
inotify_ctx *inotify = calloc(1, sizeof(inotify_ctx));
fd = inotify_init();
inotify->fd = fd;
/* if (inotify_fd == -1) {
perror("inotify_init");
exit(EXIT_FAILURE);
}*/
evutil_make_socket_nonblocking(inotify->fd);
//wd =
inotify_add_watch(inotify->fd, "crl_cache.txt", IN_CLOSE_WRITE);
/* if (wd == -1) {
perror("inotify_add_watch");
exit(EXIT_FAILURE);
}*/
inotify->bev = bufferevent_socket_new(ev_base, inotify->fd, BEV_OPT_CLOSE_ON_FREE);
bufferevent_setcb(inotify->bev, inotify_cb, NULL, NULL, &buf);
bufferevent_enable(inotify->bev, EV_READ);
return inotify;
}
void inotify_cleanup(inotify_ctx* inotify) {
bufferevent_free(inotify->bev);
close(inotify->fd);
free(inotify);
}