46 debug ( 4,
"type == %x; is_created == %x; is_deleted == %x", type, is_created, is_deleted );
63 debug ( 3,
"select with timeout %li secs (fd == %u).", tv_p->tv_sec, inotify_d );
66 FD_SET ( inotify_d, &rfds );
67 return select ( inotify_d + 1, &rfds, NULL, NULL, tv_p );
70#define INOTIFY_HANDLE_CONTINUE {\
71 ptr += sizeof(struct inotify_event) + event->len;\
78 static struct timeval tv = {0};
83 FD_SET ( inotify_d, &rfds );
84 char *path_rel = NULL;
85 size_t path_rel_len = 0;
86 char *path_full = NULL;
87 size_t path_full_size = 0;
89 while ( select ( FD_SETSIZE, &rfds, NULL, NULL, &tv ) ) {
91 size_t r = read ( inotify_d, buf,
BUFSIZ );
94 error (
"Got error while reading events from inotify with read()." );
96 goto l_inotify_handle_end;
100 g_hash_table_remove_all ( indexes_p->
fpath2ei_ht );
105 while ( ptr < end ) {
106 struct inotify_event *
event = (
struct inotify_event * ) ptr;
111 debug ( 2,
"Cleaning up info about watch descriptor %i.",
event->wd );
112 indexes_remove_bywd ( indexes_p,
event->wd );
117 char *fpath = indexes_wd2fpath ( indexes_p,
event->wd );
119 if ( fpath == NULL ) {
120 debug ( 2,
"Event %p on stale watch (wd: %i).", (
void * ) (
long )
event->mask,
event->wd );
124 debug ( 2,
"Event %p on \"%s\" (wd: %i; fpath: \"%s\").", (
void * ) (
long )
event->mask,
event->len > 0 ?
event->name :
"",
event->wd, fpath );
126 size_t path_full_memreq = strlen ( fpath ) +
event->len + 2;
128 if ( path_full_size < path_full_memreq ) {
129 path_full = xrealloc ( path_full, path_full_memreq );
130 path_full_size = path_full_memreq;
133 if (
event->len > 0 )
134 sprintf ( path_full,
"%s/%s", fpath,
event->name );
136 sprintf ( path_full,
"%s", fpath );
147 st_mode = (
event->mask &
IN_ISDIR ? S_IFDIR : S_IFREG );
151 st_mode = lst.st_mode;
152 st_size = lst.st_size;
156 if (
sync_prequeue_loadmark ( 1,
ctx_p, indexes_p, path_full, NULL, lst_p, r.
objtype_old, r.
objtype_new,
event->mask,
event->wd, st_mode, st_size, &path_rel, &path_rel_len, NULL ) ) {
158 goto l_inotify_handle_end;
171 if ( path_full != NULL )
174 if ( path_rel != NULL )
183 debug ( 3,
"Closing inotify_d" );
184 return close ( inotify_d );
enum eventobjtype eventobjtype_t
#define debug(debug_level,...)
int inotify_handle(ctx_t *ctx_p, indexes_t *indexes_p)
int inotify_deinit(ctx_t *ctx_p)
#define INOTIFY_HANDLE_CONTINUE
int inotify_wait(ctx_t *ctx_p, struct indexes *indexes_p, struct timeval *tv_p)
static void recognize_event(struct recognize_event_return *r, uint32_t event)
int inotify_add_watch_dir(ctx_t *ctx_p, indexes_t *indexes_p, const char *const accpath)
#define privileged_lstat64(a, b, c)
#define privileged_inotify_add_watch(a, b, c, d)
eventobjtype_t objtype_old
eventobjtype_t objtype_new
int sync_prequeue_unload(ctx_t *ctx_p, indexes_t *indexes_p)
int sync_prequeue_loadmark(int monitored, ctx_t *ctx_p, indexes_t *indexes_p, const char *path_full, const char *path_rel, stat64_t *lst_p, eventobjtype_t objtype_old, eventobjtype_t objtype_new, uint32_t event_mask, int event_wd, mode_t st_mode, off_t st_size, char **path_buf_p, size_t *path_buf_len_p, eventinfo_t *evinfo)